The best way to describe my problem is with an example...

Consider,

$content = "This is a string <kjfkldsjf> <jslkdjfksd>";

What I want to do is clear everything in between the <...> tags no matter how long the length of text in between the left and right arrows < > is.

So to be able to make the $content only equal everything other than what's in the left and right arrow. I know it already doesnt print whats in those less than and more than tags but if the data is stored in mysql then it does print them and I dont want to print them.

PLEASE HELP!

Member Avatar for diafol
$content = "This is a string <a href="link.html"> and <?php echo "stuff"?>";
echo strip_tags($content);
//gives: This is a string and stuff

You can allow certain tags with strip_tags if you need.
You can't strip 'stuff' as it's processed before any stripping.

you could strip with regex though to only strip a tags:

echo preg_replace("/<a\b[^>]*>(.*?)<\/a>/",'${1}',$str);

I'm no regex guru, so somebody else?

Ahh damn! That strip tags thing works well but I think I'm going to have to rearrange the whole database. I was displaying content on my website through mysql and at a few points needed to put some <a href> links in and some lists with <li>.

Since I'm using a search function on my website, mysql first checks for everything in the database which is typed so even if the tags are deleted afterwards - some content which contained the tags can be printed in the search results (without the tags) which also doesn't really look right.

I hate redesigning the database from scratch!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.