Jump to content
Larry Ullman's Book Forums

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):

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

//Sort values
sort($sorted_words);

//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,

Luis.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...