Jump to content

Replace line breaks with </li><li> (perhaps a PH


Viper007Bond

Recommended Posts

Okay, I want to enter into a box some lines that will be stored in one cell. Anyway, when I press \"enter\" and make a new line in the box, I want those line breaks to be replaced with \"</li><li>\" so that I can do:

 

<li>$text_from_database</li>

and it\'ll make a list.

 

Should I do this through some PHP method or should I have it enter it into the table and then run a SQL REPLACE command and replace... whatever line break is with </li><li>?

 

Explain to me how to do what you suggest please. Thanks a bunch. :)

Link to comment
Share on other sites

Hmmm, interesting. Well, I have not tried this using line breaks, but I have with other symbols. What you need is the str_replace function. It will replace the specified symbol/space/whatever with whatever you choose.

 

On the porcess PHP page (the one where you INSERT the information), run the variable (which holds all the info that you entered) through this:

 

$replace = str_replace("/n", "</li><li>", "$string");

 

Where $string is the information. I am totally not sure if it will accept the /n as a line break :S If any errors popup, change that to || or some other obscure symbol, and use symbols to define the </li><li>

 

Oh yeah, and enter the $replace variable into the database, and not the old $string (or WHATEVER) :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.