views:

34

answers:

3
$text = file_get_contents('http://www.example.com/file.php?id=name');
echo preg_replace('#<a.*?>.*?</a>#i', '', $text)

the link contains this content:

text text text. <br><a href='http://www.example.com' target='_blank' title='title' style='text-decoration:none;'>name</a>

what is the problem at this script?

+1  A: 

Tempted to flag your question, but there's no option for "Report user for summoning Cthulhu"

I'd recommend reading: http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html

RegEx is very poor and not at all intended to parse HTML. That's why there are HTML parsing libraries. Find and use one for PHP. :)

Robbie
A: 

use <a[^>]+>[^<]*</a> (works fine as long as theres just text and no tags inside the a element)

Hannes