Jump to content

extract url from anchor tag


ira19

Recommended Posts

[quote author=ToonMariner link=topic=106459.msg425873#msg425873 date=1157110986]
$tag = '<a href="www.url.com/index.html">';
$url = ereg_replace('/<a href="(?!")">/','\1',$tag);
[/quote]

ereg does not support negative lookaheads, and even if you go to preg, the expression with not work. You're telling it to find a double quote that is not followed by a double quote, that is followed by a double quote: an impossibility.
Thanks for the help but let me explain in details what i exactly need.
  I want to search say www.domainname.com in other sites say www.ab.com,www.cc.com
  When i find that the domainname is present i want to retrieve the link as well as the text
i.e <a href="http://www.domainname.com">My domain</a>
the anchor text may also be like
<a href="http://www.domainname.com" target="_blank">My domain</a>
or
<a href="http://www.domainname.com"><font size="2">My domain</font></a>
and the output should be [b]www.domainname.com [/b]and [b]My domain[/b].

Please help!!!


Here's what I got about it:
you want to have
    [B]< a href="an_absolute_path/optional/folder/file">an_absolute_path</ a> <strong>label_name</strong>[/B]
from something like
      [B]< a href="an_absolute_path/optional/folder/file"><span>label_name</span></ a>[/B]


[CODE]

$rex = '/(<a.+?href="https?:\/\/([^"]+?)(?:\/[^"]+)*".*?>)(.+?)<\/a>/iex' ;
$rpl = '"$1$2</a> <strong>".strip_tags("$3")."</strong>"' ;
$res =  preg_replace( $rex,$rpl,$string ) ;

[/CODE]
But probably I didn't get it  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.