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

Strip HTML tags and it's contents too

8 August 2012, in

To strip tags we can use the php function strip_tags($str) but it will return the content of the tags too,

How to strip html tags and remove it's contents too ?



Post a Comment