PHP tutorial-String Manipulation: split & join strings |
||||||||||||||
String manipulation in PHPSplit and join strings functionsThe split(Separator_char, String) function is used to split a string in to an array of strings by a separating character. In this example, we split the string "PHP is powerful." by space character. Example: <?php $str="PHP is powerful."; $strarr=split(' ',$str); $limit=count($strarr); for($i=0;$i<$limit;$i++) echo $strarr[$i]."<br>"; ?> In contrast, the join(Joiner_char) is used to combine an array of strings to become a single longer string. Example: <?php $strarr=array(0=>"PHP",1=>"JavaScript",2=>"CSS"); $st=join(',', $strarr); echo $st; ?> |
| |||||||||||||
|
||||||||||||||