Explode() & Implode()

Creator:
forsaken

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 ] ) ; // Gives \"Text\" 
    
Echo ( $strArray ] ) ; // Gives \"Some Text\" 
    
Echo ( $strArray ] ) ; // 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 ) ; 
?>

... Do exactly the same thing.

Description:
The 2 functions \&quot;Explode\&quot; and \&quot;Implode\&quot; are both used in string manipulation.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options