Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

using str_replace to remove html para tags

using str_replace to remove html para tags

using str_replace to remove html para tags

I am missing something but I have successfuly imported data from an XML file but am having problems with the simplest of tasks - the data contains a string containing <p> and <p /> html tags but my attempts to remove them and replace them are failing -

$newpara=str_replace("<p />;"," ",$hdesc);

Not too familiar with str_replace so any ideas where I am going wrong? PHP newbie so be gentle with me

RE: using str_replace to remove html para tags


  1. Why you have a semicolon ( ; ) at the end of the string to replace ? Do you have it in your XML file too ?
  2. Do you need the replacement string " " ? If not, maybe strip_tags() would help you better.
  3. Sure it is XML ? <p> tags are typically HTML, which have more relaxed rules and may need the more flexible preg_replace().
  4. You know, that you can not expect 100% success from manipulating XML or HTML as plain text, right ?


RE: using str_replace to remove html para tags

Are you trying to remove just the open and closing paragraph tags (<p>) (</p>) or the tags and the content of the element (<p>this is a paragraph</p>)?


Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: using str_replace to remove html para tags

Sorry the semicolon was a typo. I am just looking to strip out the tags not the para content.

RE: using str_replace to remove html para tags

Well that's bizarre - took the line out, typed it back in exactly "as was" and it works.... sorry if I wasted anybodys time and, as usual, thanks for the help

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close