lpa,
To remove links, use strip_tags() or use HTMLPurifier.
Note: htmlpurifier has a bit of a learning curve can remove broken / poorly formed tags better than strip_tags. strip_tags will work prefectly if you know all tags are formed correctly.
If you are doing this against a large body of html and only want to remove the anchor tags, a quick google search turned up this:
$str = ''; // this would be the string containing the tags to be removed
$str_noanchor = preg_replace('/<a href="([^<]*)">([^<]*)<\/a>/', '', $str);
echo $str_noanchor;
And to make a link - and shorten it:
// found @ other forums not sure if im supposed to post links there or not.. niah
// google the function you should find it.
function hyperlink($text){
// match protocol://address/path/
$text = preg_replace_callback("#(^| |\n)([a-zA-Z]+://)([.]?[a-zA-Z0-9_/-])*#", create_function('$part',
'$text_link = (strlen($part[0]) > 19) ? substr($part[0],0,14) . "..." . substr($part[0],-2) : $part[0];
return $part[1] . "<a href=\"{$part[0]}\" title=\"Click to visit: {$part[0]}\" target=\"_blank\">{$text_link}</a>";')
, $text);
// match http://www.something
//added |\n so catches new lines as well and not links in the [url=...] tags or in quotes
$text = preg_replace_callback("#(^| |\n)(www([.]?[a-zA-Z0-9_/-])*)#", create_function('$part',
'$text_link = (strlen($part[2]) > 15) ? substr($part[2],0,10) . "..." . substr($part[2],-2) : $part[2];
return $part[1] . "<a href=\"http://{$part[2]}\" title=\"Click to visit: http://{$part[2]}\" target=\"_blank\">{$text_link}</a>";')
, $text);
// return $text
return $text;
}
You can use the general idea, instead of preg_replace they are using preg_replace_callback to use substr to limit the length of the string.
This should point you in the right direction, if the wordpress function works better for creating the links (without shortening it) try adding the callback function (from above)
Best of luck...