If you want to stay away from RegEx, you could use an ugly combination of strpos and substr to find "<a "
extract that, etc.
Something ugly like this (this only finds the first link, it will fail with bad code, and it doesn't find ' (which is invalid XHTML)) p.s. this is a bad idea:
function findLink($string) {
$pos = strpos($string, "<a ");
if ($pos === false)
return false;
$string = substr($string, $pos);
$pos = strpos($string, "href");
$string = substr($string, $pos);
// First quote
$pos = strpos($string, '"');
$string = substr($string, $pos + 1);
// Last quote
$pos = strpos($string, '"');
$string = substr($string, 0, $pos);
if (trim($string) != "")
return $string;
return false;
}
I'm sure you could also try tokenizing the string?
$token = strtok($string, "\"'");
while ($token !== false) {
// Look for anything with a link in it
str_replace(array("http://", "www", "ftp://"), "", ltrim($string), $count);
if ($count > 0)
return $string;
$token = strtok($string, "\"'");
}
return false;
Note: these are NOT great ways to do this.