Jump to content
Larry Ullman's Book Forums

Chapter 07 Explode() Implode() Separators

Recommended Posts

Hi Larry,

First of all, thanks for the book. It's being surprisingly easy to follow.


I'm currently going through chapter 07 (arrays) and I was doing the excercise in "Transforming Between Strings and Array", I first created my list.html file and then on the list.php, this is what I wrote (HTML omitted):

//Get text from form
$sorted_words = explode(' ',$_POST['words']);

//Sort values

//Turn array back into a string
$string_words = implode("<br />",$sorted_words);

//Prints string
print "<p>Alphabetized version of your text: <br />$string_words</p>";


Everything working fine. However, the moment I add something else as separator:

$sorted_words = explode(',',$_POST['words']);

It prints out the phrase exactly as entered in the form, nothing seems to happen, no errors either.

Where is the problem?


PS: I've seen you are currently working on the 5th edition of "PHP and MySQL for Dynamic Web Sites". Any updates of how is it going? Planning to buy it as song as it gets published :)


Many thanks in advance,


Link to comment
Share on other sites

  • 3 weeks later...

Thanks for the nice words! I really appreciate it. As for your question, if the separator isn't found than there's nothing to explode the next on so the result is the same as the input. In other words, if I explode abcdefghijk on %, the result is abcdefghijk. 


I haven't started the 5th edition of the PHP & MySQL book yet, so it won't be out for at least 6 months from now. But thanks for your interest!

Link to comment
Share on other sites


  • Create New...