Question:
PHP convert line breaks to paragraph tags?
mtox
2008-12-22 19:49:33 UTC
I have a form that submits data to a MySQL database and then I have a page that displays the submitted data. Some of the data is articles which means multiple paragraphs. Now I want text indents for each paragraph but I only know how to do those in HTML paragraph tags. Is there any PHP function or whatever that can do this for me? I already have 'nl2br', are there any others?
Four answers:
?
2008-12-23 02:23:06 UTC
if "$txt" is your text: (ie bla-bla< rb />blabla< rb />)

[ I am using "rb" because this editor converts "b r" ! ]



$txt = str_replace ( "< rb / >", "< /p >< p >", $txt );

// replaces all br with "end para" "para" tags.

Then:

$txt = "< p > " . $txt; // to add the first one!

Finally:

$l = strlen ($txt) - 3; // 3 is the length of the last

you have added!

$txt = substr ($txt, 0, $l);



(You MAY have to review this if you stored into a "TEXT" type: there will be "invisible" \r\n you will also have to replace with < rb >!

$txt = str_replace ("\r\n", " < r b / > ", $txt);

anonymous
2008-12-24 00:26:23 UTC
I found a site good for programmers to ask questions. There are some experienced programmers there, so you can get help there. Registration is free by the way.



http://www.geekpolice.net/
?
2016-10-18 08:03:41 UTC
Use css to set the demonstrate characteristic to inline. however the element of p tags is to set aside self reliant paragraph blocks, so... what's the semantical which technique of regardless of you opt to insert?
anonymous
2008-12-22 19:57:04 UTC
nl2br will probably do what you need, but if you need more you'll probably have to write a little parser.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...