<?php
// SET TEXT TO BE USED
$string = 'some text some text <b>some text</b> some text <a href=http://sometextsometext<b>sometext</b>sometextsometext>text</a> some text some text. And We Have A <a href=http://google.com>Google</a> Link' ;
// USE A CALLBACK FUNTION TO SCAN THROUGH LINKS
print $string ;
// THIS IS THE CALLBACK FUNCTION ... EACH LINK IS STORED AS '$m'
function remove_crap_from_links( $m ) {
// PULL OUT THE PART OF THE LINK BEFORE THE CLOSING LINK BRACKET
// (USE A NEGATIVE LOOKAHEAD TO MAKE SURE THAT IT CAN'T HAVE ANY OPENING/CLOSING HTML BRACKETS IN THERE
if ( preg_match ( '~<a(.*?)>(?:[^<>]*?)</a>~i' , $m [ 0 ] , $url_matches ) ) {
// RUN A PHP strip_tags FUNCTION TO PULL OUT ANY HTML TAGS FOUND IN THE LINK BODY
// REBUILD THE URL, USING THE $stripped_url IN PLACE OF WHAT WAS ALREADY THERE
$clean_url = preg_replace ( '~(<a)(.*?)(>(?:[^<>]*?)</a>)~' , '$1' . $stripped_url . '$3' , $m [ 0 ] ) ;
}
return $clean_url ;
}
PD9waHAKCgovLyBTRVQgVEVYVCBUTyBCRSBVU0VECiRzdHJpbmcgPSAnc29tZSB0ZXh0IHNvbWUgdGV4dCA8Yj5zb21lIHRleHQ8L2I+IHNvbWUgdGV4dCA8YSBocmVmPWh0dHA6Ly9zb21ldGV4dHNvbWV0ZXh0PGI+c29tZXRleHQ8L2I+c29tZXRleHRzb21ldGV4dD50ZXh0PC9hPiBzb21lIHRleHQgc29tZSB0ZXh0LiAgQW5kIFdlIEhhdmUgQSA8YSBocmVmPWh0dHA6Ly9nb29nbGUuY29tPkdvb2dsZTwvYT4gTGluayc7CgoKLy8gVVNFIEEgQ0FMTEJBQ0sgRlVOVElPTiBUTyBTQ0FOIFRIUk9VR0ggTElOS1MKJHN0cmluZyA9IHByZWdfcmVwbGFjZV9jYWxsYmFjaygnfjxhLio/PC9hPn4nLCAncmVtb3ZlX2NyYXBfZnJvbV9saW5rcycsICRzdHJpbmc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