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.
Link to comment
Share on other sites

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!!!


Link to comment
Share on other sites

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  :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.