jwhite68 Posted July 15, 2007 Share Posted July 15, 2007 I have used the strip_tags function to remove html from a string with reasonable success. But it still leaves /r/n characters. I've hunted around on various forums for solutions, and every time someone suggests a solution, it actually doesnt work. Here is the code: $html_string='<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US">The village of Sechishte is 40 km from the town of Shumen and 90 km from Varna city.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>\r\n<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"> <o:p></o:p></SPAN></P>\r\n<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US">This 120 sq m house, consisting of 6 rooms has a huge piece of land of 5 000 sq m. It is a corner plot with an additional small house and a barn on it.<o:p></o:p></SPAN></P>\r\n<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US">Bathroom/WC are on the ground floor of the house.<o:p></o:p></SPAN></P>'; $string=strip_tags($html_string); echo $string; $value = eregi_replace("\n\r","",$string); echo $value; The forst echo show the strip of html which leaves in the \r\n newlines. The second is one solution a forum suggested for removing newlines which doesnt work. Anyone got any suggestions? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 15, 2007 Share Posted July 15, 2007 Try: <?php $html_string = '<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US">The village of Sechishte is 40 km from the town of Shumen and 90 km from Varna city.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>\r\n<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"> <o:p></o:p></SPAN></P>\r\n<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US">This 120 sq m house, consisting of 6 rooms has a huge piece of land of 5 000 sq m. It is a corner plot with an additional small house and a barn on it.<o:p></o:p></SPAN></P>\r\n<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US">Bathroom/WC are on the ground floor of the house.<o:p></o:p></SPAN></P>'; $string = strip_tags($html_string); echo $string; echo '<hr />'; $value = str_replace('\r\n', '', $string); echo $value; ?> Quote Link to comment Share on other sites More sharing options...
jwhite68 Posted July 15, 2007 Author Share Posted July 15, 2007 That did the trick. Many thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.