Get Link Text
Here we find a function that uses a php regular expression to get the link text from a url such as <a href="http://www.phpro.org">Link</a>. Basically it will will catch anything between > and </a> and return that value
<?php
/**
* @get the text of a url link
*
* @param string $url
*
* @return string
*
*/
function getUrlLinkText($url)
{
/*** find the link test ***/
preg_match('/\>(.*)<\/a>/', $url, $matches);
/*** return the match ***/
return $matches[1];
}
/*** example usage ***/$url = '<a href="http://www.phpro.org" class="something" id="link_id">Url Text Link Here</a>';
echo getUrlLinkText($url);
?>
0 comments:
Post a Comment