PHP: работа со строками. Строковые функции PHP

. HTML CSS, , , PHP. , -: . , PHP — , .

PHP




, PHP , , , , , . . . , mb_ (, mb_strpos()). , php.ini ;extension=php_mbstring.dll, .

echo. :





echo " "

, :

$str = " ";

echo $str;

, :

echo "" . " " . " ";

$str1 = "";

$str2 = "";

$str3 = "";

echo $str1 . $str2 . $str3;

. echo:

echo $str1 . ' ' . $str2 . ' ' . $str3;

: " ". , :

$str1 = "";

$str2 = "";

$str3 = "";

$string = $str1 . ' ' . $str2 . ' ' . $str3;

echo $string;

Echo , . , :

$i = 2;

$sum = $i + $i; // $sum 4

echo $i . " + " . $i . " = " . $sum;

: "2 + 2 = 4".

php




, ($string = " "). :

  • \n ;
  • \r ;
  • \" :
    • echo " \"\" "; // ""
  • \$ ;
  • \\ .

, PHP.





, :

$string = "My name is Yemelyan and I am 27 year old";

:

$name = "Yemelyan";

$anotherName = "Katherin";

, . strpos($str, $search). $search, , $str. false. , strpos($string, $anotherName) false, strpos($string, $name) — . ( , ):

$string = "My name is Yemelyan and I am 27 year old";

$name = "Yemelyan";

$anotherName = "Katherin";

echo strpos($string, $anotherName); // false

echo strpos($string, $name); //

, , 11 ( ).

strpos() , strrpos() .

, . : PHP . , : strpos($str, $search)!=false. PHP , , 0 false. strrpos().

, . substr_count(), : substr_count($str, $search). . , : . : substr_count($str, $search, $start, $end). $search $start $end $str. , .





PHP:

. , . "", . (, "" ""), false true. , . , PHP : "" ("", "", "" . .) .

strtolower() . , $catName = "Fluffy". strtolower($catName) "fluffy". strtoupper().

PHP:

. , PHP . strlen(), — . , strlen($str)-1, .

php




PHP:

substr(), : substr($str, $start, $end). , $string = "Fluffy cat", . , : $newString = substr($string, 1, 4). $newString = substr($string, 1), ( "luffy"). strlen(): substr($string, 1, strlen($string)).

str_replace(), : str_replace($subStr, $newSub, $str). , str_replace() . :

$str = " !";

$newStr = str_replace("", "", $str); // !

php
, -, . : intval() floatval(), $string. : intval() , floatval() - .

intval(), floatval() , , . , . , , . .

. , (, , : 88 88 + 33 33 = 8833). strval(), . : , . .

php




, . , - . PHP, .




All Articles