Marie M Posted January 28, 2020 Share Posted January 28, 2020 <!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 More sharing options...
Larry Posted January 29, 2020 Share Posted January 29, 2020 Could you clarify what you mean when you say it doesn't work? If, for example, I do echo ucwords('test'); it returns "Test". Link to comment Share on other sites More sharing options...
Marie M Posted January 30, 2020 Author Share Posted January 30, 2020 (edited) 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 January 30, 2020 by Marie M Link to comment Share on other sites More sharing options...
Marie M Posted January 30, 2020 Author Share Posted January 30, 2020 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 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 More sharing options...
Larry Posted January 30, 2020 Share Posted January 30, 2020 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 More sharing options...
Marie M Posted February 10, 2020 Author Share Posted February 10, 2020 Thanks a lot 🙏🏽 I appreciate your help. 🌹 Link to comment Share on other sites More sharing options...
Recommended Posts