Page 1 of 1

Apply striptags() selectively on <a> tags

Posted: Thu Dec 16, 2010 3:32 am
by saudepp
Hi there,
I want to apply the striptags() function selectively on <a> tags containing some specific pattern in the URL.

e.g. I have text that contains two different sorts of <a> tags:

sort 1:
<a href=/dirname1/somepage>something</a>

sort 2:
<a href=/dirname2/somepage>something</a>

note that "somepage" and "something" can vary from tag to tag. the different URL sorts can be distinguished by dirname1 or dirname2.

now, I want to scan the text and remove all <a> tags pointing to URLs that begin with /dirname1, while I want to keep all other tags.
after removal of sort 1 tags, only the anchors "something" should be left over.

how could this be done?

thanks for your help.

-saudepp

Re: Apply striptags() selectively on <a> tags

Posted: Thu Dec 16, 2010 9:52 am
by saudepp
nobody has a clue?
please help ...

Re: Apply striptags() selectively on <a> tags

Posted: Thu Dec 16, 2010 10:13 am
by pickle
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not receive a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
strip_tags() does allow you to specify a whitelist of allowed tags. If you only want to strip links, you need to specify every tag except the <a> tag.

Re: Apply striptags() selectively on <a> tags

Posted: Thu Dec 16, 2010 10:15 am
by saudepp
please read my question carefully, it's not as simple as that ...
<a> shall be removed conditional on the URL structure.

some <a> tags should survive, some other <a> tags shouldn't.

Re: Apply striptags() selectively on <a> tags

Posted: Thu Dec 16, 2010 12:20 pm
by Darhazer
saudepp wrote:please read my question carefully, it's not as simple as that ...
<a> shall be removed conditional on the URL structure.

some <a> tags should survive, some other <a> tags shouldn't.
use preg_replace

Re: Apply striptags() selectively on <a> tags

Posted: Thu Dec 16, 2010 12:51 pm
by saudepp
thanks, I am already playing with preg_replace and regular expressions.
nice, but not so easy to learn ...

cheers

I wann use it on this page: Wellnessoase