• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

need help in regular expression

i need your help in php regular expression
how to extract all url from anchor tag like
<a href="http://lt.php.net/" class=l onmousedown="return clk(this.href,'','','res','1','')">PHP: Hypertext Preprocessor</a>
i want to extract http://lt.php.net/ using regular expression from above
 
PHP:
<?
function extract_url( $string )
{
	if( preg_match( '~href=["|\'](.*?)["|\']~', $string, $url ) )
	{
		return $url[1];
	}
}

echo extract_url( 'the url is in the <a href="http://krakjoe.com">anchor</a> text' );
echo "<br />\n";
echo extract_url( "the url is in the <a href='http://krakjoe.com'>anchor</a> text" );
?>
 
Back
Top