-1

Possible Duplicate:
PHP to clean-up pasted Microsoft input

Hi help using regex or any php function that can remove

<o:p></o:p> or <o:p>&nbsp;</o:p> or <o:p> </o:p> 

from my string

Example

<p class=MsoNormal>Category: Paul :asadad<o:p></o:p></p><p class=MsoNormal>Car: Toyota <o:p> </o:p></p><p class=MsoNormal>Sports: Soccer<o:p>&nbsp;</o:p></p>

I need it to be

<p class=MsoNormal>Category: Paul :asadad</p><p class=MsoNormal>Car: Toyota 1</p><p class=MsoNormal>Sports: Soccer</p>

Thanks a lot :)

Community
  • 1
  • 1
redknight
  • 39
  • 6
  • So what regex have you managed so far? – Jonnix Oct 04 '12 at 10:06
  • if you just want to remove the elements, you can use `str_replace`. apart from that, there is plenty of answers showing how to remove elements with an XML parser on StackOverflow, so give it a search please. – Gordon Oct 04 '12 at 10:09
  • Check http://stackoverflow.com/search?q=is%3Aanswer+removeChild+[php]&submit=search – Gordon Oct 04 '12 at 10:15
  • Hmmm do you have any idea if the FCKEditor cleanup script can be called by php without using JS. I think that would help me a lot – redknight Oct 05 '12 at 01:03

3 Answers3

0
<?php
   $str =  '<p class=MsoNormal>Category: Paul :asadad<o:p></o:p></p><p class=MsoNormal>Vessel Name: Vessel 1<o:p> </o:p></p><p class=MsoNormal>Sub Category: asdasdad<o:p>&nbsp;</o:p></p>';
   $pattern = '#(<o:p>\s*[\&nbsp;]*\s*<\/o:p>)#';
   $str = preg_replace($pattern, '', $str);
   echo $str;
Surace
  • 701
  • 3
  • 8
0

If you are using PHP, why don't you just use the strip_tags() function? I would give it a shot, you can even specify tags, you want to left in the text. See the link for more details.

Richard Otvos
  • 196
  • 1
  • 12
0
preg_replace('#<o:p>(\s|&nbsp;)*</o:p>#', '', $text);
maalls
  • 749
  • 8
  • 20