From The Blog

PHP: Regex match anchor text and url in a string

12 November 2013, in

To match anchor text and url in a string:

$sourcestring = 'this is a good test <strong><a href="http://wordpress.org">file (.docx)</a></strong> 
and this is the new <a href="wp-content/uploads/amir.jpg">site image</a> ';

preg_match_all('/<a[^>]+href=[\'|"]([^>]+)[^>]+>([^<]+)<\/a>/i',$sourcestring,$matches);

var_dump($matches);



Post a Comment