LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-22-2013, 09:55 AM   #1
audiodef
LQ Newbie
 
Registered: Sep 2008
Posts: 12

Rep: Reputation: 0
PHP, nl2br except between HTML tags?


How would I write a PHP function to use nl2br except between any two HTML tags? For example, the following:

Code:
Blah, blah, blah. Here is some text.

And now here is some more text.

<table>
<tr>
<td>
Followed by stuff in a table.
</td>
</tr>
</table>
I don't want the table exploded into extra line breaks by nl2br because the text within it won't appear spaced correctly. However, there should be new lines between the first two lines of text as it appears above. I want this all handled by one function because this will all be one string retrieved from database tables. Of course, I'm open to any exploding of the original string to facilitate this.
 
Old 07-22-2013, 11:42 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
I can't think of any good (emphasis on that 'good') way to do this except through using a full-blown HTML parser. Perhaps it may be easier to just amend the database tables so they have the <br/> in them already?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using tr strip away html tags Micky12345 Linux - Newbie 5 03-17-2012 01:03 PM
Html tags inside PHP mail body message. linuxlover.chaitanya Programming 7 03-12-2010 12:50 AM
[mod]_python: is there an equivilent to php's nl2br? BrianK Programming 2 05-12-2008 12:35 PM
mutt and html tags cizzi Linux - Software 3 03-30-2008 08:21 PM
strip html tags rblampain Programming 6 08-07-2005 06:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration