Question for all your smart people out there.
I want to write a script that I can pass a large amount of HTML though that will remove all of the <a> tags within the file. Possible?
Removing tags from HTML code with PHP
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I've been working on a script like this for a site I am doin. Gathering information from another webpage and here is what I've come up with. I don't know how efficient it is but it works for the load I have. Maybe you can get some ideas from this.
This first part strips all the <a> tags, no matter what's in between.
And to remove the </a> tags..
You can do that for any of the html tags, just replace what you need.
$value is a string with everything that was gathered form the webpage I grabbed, so these functions search out the <a blah blah> tags and replaces it with "", which in effect, deletes it and replaces it with nothing.
Hope I could help, good luck!
geoff
This first part strips all the <a> tags, no matter what's in between.
Code: Select all
<?php
$value = eregi_replace("<a[^>]*>","",$value);
?>Code: Select all
<?php
$value = str_replace("</a>","",$value);
?>$value is a string with everything that was gathered form the webpage I grabbed, so these functions search out the <a blah blah> tags and replaces it with "", which in effect, deletes it and replaces it with nothing.
Hope I could help, good luck!
geoff