Jump to content
Larry Ullman's Book Forums

Recommended Posts

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
</head>
<body>
  
  <?php
  
  $string_array = explode(' ' , $_POST['words']);
  $array_string = implode(',<br>' , $string_array);
  $array_string = ucwords(strtolower($array_string));
  print "<p> Alphabetized:<br><br>$array_string</p>";
  
  ?>
  
</body>
</html>

 

Share this post


Link to post
Share on other sites

Could you clarify what you mean when you say it doesn't work? If, for example, I do 

echo ucwords('test');

it returns "Test". 

Share this post


Link to post
Share on other sites

It might be working for one word but it doesn't work for the string of words.

Is it supposed to work on a single word only?

I apologize for not being able to post the whole code here(technical issues I guess).

The idea is that you input some words separated by space.

explode() converts the words to an array.

Then implode() changes it back to string.

after implode() happens, I need to convert the first letter of every word to uppercase.

Do you think it's possible?

Edited by Marie M

Share this post


Link to post
Share on other sites

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I adore your website, and just thought that there is a need to give you small feedbacks about my experience.

1) I couldn't post my html and php codes separately.

2) later, tried to add html code underneath the php code but it didn't allow me to insert anymore code to an existing one.

3) Didn't get notified about your reply.

I'm very thankful for anything you do for us Larry.

This forum feels like a huge rescue to me because it doesn't kick me out if I ask a question in a  wrong way like other websites do.

And your books are amazing! 

Share this post


Link to post
Share on other sites

Thanks for the nice words and sorry for the problems! 

I just did this:

echo ucwords('this is a test');
This Is A Test

I wonder if it's because you're adding the ,<br> and then doing the ucwords(). Try it this way:

  $string_array = ucwords(strtolower($_POST['words']));
  $array_string = explode(' ' , $string_array);
  $string_array = implode(',<br>' , $array_string);

 

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.
Note: Your post will require moderator approval before it will be visible.

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...