0

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!

Edited by asif49: n/a

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by asif49
0
$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?

Edited by diafol: n/a

-1

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!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.