User Tools

Site Tools


phpsqlet:string_functions

string functions

.=

$un = "";
$un .= "un";

lower/uppercase etc.

  • strtolower($String) → lowercase
  • strtoupper($String) → uppercase
  • ucfirst($String) → capitalize first character
  • ucwords($String) → capitalize words

length

echo strlen("un"); // 2

trim

Remove leadin or trailing whitespace.

echo "A" .trim(" B C D ") . "E"; // "AB C DE"

find

Retourne le string recherché et tout ce qui suit.

$str = "vamos a la playa";
echo strstr($str, "la"); // "la playa"
echo strstr($str, "yolo"); //  rien

replace

$str = "vamos a la playa";
echo str_replace("la playa", "bailar la bamba", $str); // vamos a bailar la bamba

repeat

$str = "go ! ";
echo str_repeat($str, 3); // "go ! go ! go ! "

make substring

$str = "0123456789";
echo substr($str, 1,8); // "12345678";

find position

$str = "0123456789";
echo strpos($str, "234"); // 2

find character

$str = "0123456789";
echo strchr($str, "8"); // "89"
echo strchr($str, "a"); // rien
$str = "abba";
echo strchr($str, "a"); // "abba"
$str = "gabba";
echo strchr($str, "a"); // "abba"
phpsqlet/string_functions.txt · Last modified: 2016/04/13 15:00 by leo