Link to home
Start Free TrialLog in
Avatar of egoselfaxis
egoselfaxis

asked on

Seeking a PHP code snippet that loops through multiple lines in a textarea and turns it into an unordered list

I'm looking for a PHP code snippet that loops through multiple lines in a textarea and turns it into an unordered list.

For example, users would paste the text similar to the following into a textarea (with a hard carriage return after each line):

Hand carved double wood entry doors
Wood flooring and wood detailed ceiling with custom moldings
Breakfast bar with sink, refrigerator and cabinetry
Large bedroom with views of the Intracoastal Waterway
French doors lead out to a private covered patio with fireplace

Open in new window


.. and I'd like to convert it to the following -- on the fly -- using PHP:

<ul>
     <li>Hand carved double wood entry doors</li>
     <li>Wood flooring and wood detailed ceiling with custom moldings</li>
     <li>Breakfast bar with sink, refrigerator and cabinetry</li>
     <li>Large bedroom with views of the Intracoastal Waterway</li>
     <li>French doors lead out to a private covered patio with fireplace</li>
</ul>

Open in new window


I believe the main challenge is that I have to turn this into some kind of list or array (using the hard carriage returns as delimiters) and to then loop through that list to stiitch everything back together into an unordered list.

How would I accomplish this using PHP?

Thanks,
- Yvan
ASKER CERTIFIED SOLUTION
Avatar of Jim Riddles
Jim Riddles
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of egoselfaxis
egoselfaxis

ASKER

That worked great -- thank you!

- Yvan
Excellent.  Please mark my answer as the solution to close this question.  Have a great day!