PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
i'm not sure how to accomplish this so i'm wondering if anyone has any pointers:
when i import an email into a mysql and then display it on a page, i'm getting content double spaced and for the life of me i can't seem to get rid of them. i need to strip all html except spaces and breaks because some output is saved from outlook and has ms word formatting which screws up the page. when i display content everything displays ok with the following code, except that sometimes the content is double spaced. any ideas?
The quick brown<br />
fox jumped over<br />
the lazy dog.
Notice that each line is terminated by a <br> tag and an invisible newline. When you use nl2br(), an additional <br> tag is added for each newline, making the content double-spaced.
in looking at the page source code, it's not <br> that's causing the breaks, its actually <p class=MsoNormal> </p>
is there a way to replace <p class=MsoNormal> </p> with just <br/>?
the quick brown fox ran across the street and again
when i look at the page source code, i see:
<td><div><p class=MsoNormal>the quick brown fox ran across the street</p><p class=MsoNormal>the quick brown fox ran across the street again</p><p class=MsoNormal>the quick brown fox ran across the street and again</p></div></td>
so what i need to do is replace <p> with <br> so that the text appears as:
the quick brown fox ran across the street
the quick brown fox ran across the street again
the quick brown fox ran across the street and again
// The input string:
$subject = '<td><div><p class=MsoNormal>the quick brown fox ran across the str'.
'eet</p><p class=MsoNormal>the quick brown fox ran across the street again'.
'</p><p class=MsoNormal>the quick brown fox ran across the street and agai'.
'n</p></div></td>';
// Appends a break tag after every paragraph
$subject = str_replace('</p>', '</p><br />', $subject);
// Strips all HTML tags except <br>
$subject = strip_tags($subject, '<br>');
// The output string:
$subject == 'the quick brown fox ran across the street<br />the quick brown fo'.
'x ran across the street again<br />the quick brown fox ran across the str'.
'eet and again<br />';