Jump to content
Larry Ullman's Book Forums

ucwords() doesn't work


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>

 

Link to comment
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
Link to comment
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! 

Link to comment
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);

 

Link to comment
Share on other sites

  • 2 weeks later...
 Share

×
×
  • Create New...