Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using str_replace to remove html para tags

Status
Not open for further replies.

sunbase

Technical User
Jun 18, 2009
15
0
0
GB
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
 
Hi

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

Feherke.
feherke.ga
 
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>)?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Sorry the semicolon was a typo. I am just looking to strip out the tags not the para content.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top