The 2 functions "Explode" and "Implode"; are both used in the splitting of a string into several pieces or the joining of an array together. For those of you familiar with JS, \"Explode\" is very similar to \"innerHTML.Split\". The syntax of \"Explode\" is:
Explode ( Split By , String ) ;
<?php
$strString = "Text;Some Text;More Text" ;
$strArray = Explode ( ";\" , $strString ) ;
?>
In this example \"Explode\" takes the string and splits it into several pieces by \";\" creating an array with 3 items. If these were echoed...
<?php
Echo ( $strArray [ 0 ] ) ; // Gives \"Text\"
Echo ( $strArray [ 1 ] ) ; // Gives \"Some Text\"
Echo ( $strArray [ 2 ] ) ; // Gives \"More Text\"
?>
Now \"Implode\" can be used to reverse this, the syntax of which is:
Implode ( Join With , Array ) ;
<?php
$strArray = Array ( "Text\" , \"Some Text\" , \"More Text\" ) ;
$strString = Implode ( \";\" , $strArray ) ;
?>
In this example Implode takes the array and joines it together as a string with \";\" inbetween each piece of text. If this was echoed...
<?php Echo ( $strString ) ; // Gives \"Text;Some Text;More Text\" ?>
Final Notes: The function \"Join\" is exactly the same as \"Implode\" thus...
<?php
$strString = Join ( ";\" , $strArray ) ;
$strString = Implode ( \";\" , $strArray ) ;
?>
Comments
Post new comment