Search code examples
phpstringhyperlinkextracthref

PHP extract link from <a> tag


Possible Duplicate:
PHP String Manipulation: Extract hrefs

I am using php and have string with content =

<a href="www.something.com">Click here</a>

I need to get rid of everything except "www.something.com" I assume this can be done with regular expressions. Any help is appreciated! Thank you


Solution

  • This is very easy to do using SimpleXML:

    $a = new SimpleXMLElement('<a href="www.something.com">Click here</a>');
    echo $a['href']; // will echo www.something.com