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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing HTML tags and the code in between

Status
Not open for further replies.

glimbeek

Programmer
Nov 30, 2009
83
NL
Hi,

I have the following HTML code:
Code:
A line of text, which is of any length. Ohw yes it is!<br /><br />
<h2>And a header</h2>
<img src="image.jpg>With an image and a <a href="/">link</a>. With some more text.

After "cleaning" the code, I want to end up with the following:
Code:
A line of text, which is of any length. Ohw yes it is! With an image and a <a href="/">link</a>. With some more text.

AKA, I want to remove all the HTML tags except the link

I searched on Google, this forum and others.
I tried regular expressions combined with preg_
I tried I tried Nothing seemed to work.

In the end I ended up with the following:
Code:
$string        = $this->item->fulltext;
$search        = array('/\<(.+)>(.*)>/si'); //Strip out HTML tags
$string        = preg_replace($search, '', $string);

I do believe that using a reg express should be the way to go, but I'm struggling of coming up with one that covers everything I need.

Any help would be greatly appreciated.

With kind regards,
George
 
You ask different questions at different points in time. So it is difficult to determine what you want. And you still have not answered my question about nested tags.

However if your code works for you then that's great. Nothing more to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top