0

I am attempting to remove formatting from copied text off of another website. I can use preg_replace along with other methods, but I want to keep <p>'s and such, but remove formatting such as <font>.

Here is what I'm using right now to clean my text currently:

mysql_real_escape_string(str_replace("\r\n",'', $_POST['maintext']));

12
  • 9
    php.net/strip_tags and observe the 2nd optional argument (allowed tags)
    – Marc B
    May 9, 2012 at 20:15
  • 2
    Consider using array("\r", "\n") as your first param to str_replace() since not all line breaks are exactly \r\n.
    – Mike B
    May 9, 2012 at 20:17
  • @MarcB +1 why don't you write it as an answer?
    – Shomz
    May 9, 2012 at 20:20
  • I used strip_tags($maintext, '<p><a>'); and it still stripped the <p> even though it isn't supposed to.
    – drummer392
    May 9, 2012 at 20:22
  • @drummer392 You'll have to provide an example. The example in the manual is pretty clear.
    – Mike B
    May 9, 2012 at 20:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.