Академический Документы
Профессиональный Документы
Культура Документы
com
Length : It is an optional parameter. It specifies the length of the string which is to be extracted.
Example 1:
<?php echo substr("Hello world",6); ?> //Returns world
Example 2 :
<?php echo substr("Hello world",6,4); ?> // Returns worl
Example 3 :
<?php echo substr("Hello world", -1); ?> // Returns d
Example 4:
<?php echo substr("Hello world", -3, -1); ?> // Returns rl
strlen()
This function returns the length of the string
Syntax :
strlen(<string>);
Explanation:
String : It is mandatory field. The string whose length is to be found out is mentioned here.
Example 1:
Important String functions in PHP
MyPHPScriptz.com
MyPHPScriptz.com
str_replace()
The str_replace() function replaces some characters with some other characters in a string.
This function works by the following rules:
Syntax :
str_replace(<search>,<replace>,<string/array>,[<count>]);
Explanation :
Search : It is mandatory . The string or value to be searched comes here.
Replace : It is mandatory. The string or value to be replaced comes here.
String/Array : It is mandatory. The string or array in which the value is to be found out comes here.
Count : It is optional. It counts the number of replacements to be done.
Example 1:
<?php echo str_replace("world","Peter","Hello world"); ?>// Returns Hello Peter
Example 2:
<?php
$arr = array("blue","red","green","yellow");
Important String functions in PHP
MyPHPScriptz.com
Syntax :
strcmp(<string1>,<string2>);
Explanation :
String1 : It is mandatory. The first string comes here.
String 2 : It is mandatory. The Second string comes here.
Example 1:
<?php echo strcmp("Hello world!","Hello world!"); ?> //Returns 0
Note: The strcmp() function is binary safe and case-sensitive. For case insensitive comparison you
can use strcasecmp(<string1>,<string2>); function. It is similar to strcmp() function.
explode()
This function breaks the string into array on the basis of delimiter passed.
Important String functions in PHP
MyPHPScriptz.com
MyPHPScriptz.com