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? Link to comment https://forums.phpfreaks.com/topic/60077-solved-stripping-html-text-and-newline-characters-from-string/ 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; ?> Link to comment https://forums.phpfreaks.com/topic/60077-solved-stripping-html-text-and-newline-characters-from-string/#findComment-298801 Share on other sites More sharing options...
jwhite68 Posted July 15, 2007 Author Share Posted July 15, 2007 That did the trick. Many thanks. Link to comment https://forums.phpfreaks.com/topic/60077-solved-stripping-html-text-and-newline-characters-from-string/#findComment-298846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.