$php_mysql$ Posted May 30, 2012 Share Posted May 30, 2012 friends this function creates keywords but i am having a issue, if there is a link on my string then the output that this function gives is like: httpwwwsomesitecomdetailsphpid123456 now how to make it that if it finds any http://www.somesite.com/details.php?id=123456, www.somesite.com/details.php?id=123456 or somesite.com/details.php?id=123456 than it ignores the Hyperlink and do not show anything on the output. basically ignore any sort of hyperlinks. function metakeyword($string){ $stopWords = array('i','a','about','an','and','are','as','at','be','by','com','de','en','for','from','how','in','is','it','la','of','on','or','that','the','this','to','was','what','when','where','who','will','with','und','the','www'); $string = preg_replace('/\s\s+/i', ' ', $string); // replace whitespace $string = trim($string); // trim the string $string = preg_replace('/[^a-zA-Z0-9 -]/', '', $string); // only take alphanumerical characters, but keep the spaces and dashes too… $string = strtolower($string); // make it lowercase preg_match_all('/\b.*?\b/i', $string, $matchWords); $matchWords = $matchWords[0]; foreach ( $matchWords as $key=>$item ) { if ( $item == '' || in_array(strtolower($item), $stopWords) || strlen($item) <= 3 ) { unset($matchWords[$key]); } } $wordCountArr = array(); if ( is_array($matchWords) ) { foreach ( $matchWords as $key => $val ) { $val = strtolower($val); if ( isset($wordCountArr[$val]) ) { $wordCountArr[$val]++; } else { $wordCountArr[$val] = 1; } } } arsort($wordCountArr); $wordCountArr = array_slice($wordCountArr, 0, 15); return $wordCountArr; } Please help me out you genius people Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/263374-remove-hyperlinks-from-string/ Share on other sites More sharing options...
scootstah Posted May 30, 2012 Share Posted May 30, 2012 Try encapsulating the function body with: if (!filter_var($string, FILTER_VALIDATE_URL)) { // function body } Link to comment https://forums.phpfreaks.com/topic/263374-remove-hyperlinks-from-string/#findComment-1349750 Share on other sites More sharing options...
$php_mysql$ Posted May 30, 2012 Author Share Posted May 30, 2012 not sure how to do it Link to comment https://forums.phpfreaks.com/topic/263374-remove-hyperlinks-from-string/#findComment-1349753 Share on other sites More sharing options...
Barand Posted May 30, 2012 Share Posted May 30, 2012 this was my plan A, but I'll take a look at filter_var as plan B <?php $str = "friends this function creates keywords but i am having a issue, if there is a link on my string then the output that this function gives is like: httpwwwsomesitecomdetailsphpid123456 now how to make it that if it finds any http://www.somesite.com/details.php?id=123456, www.somesite.com/details.php?id=123456 or somesite.com/details.php?id=123456 than it ignores the Hyperlink and do not show anything on the output. basically ignore any sort of hyperlinks. "; echo "<p>$str</p>"; $str = preg_replace('/\s\s+/i', ' ', $str); // replace whitespace $astr = explode(' ', $str); foreach ($astr as $k => $v) { if (strlen($v)<6) continue; //ignore short ones $res = parse_url($v); if (count($res) < 2) continue; unset ($astr[$k]); // remove if looks like valid url } $str = join (" ", $astr); echo "Results<br />"; echo "<p>$str</p>"; ?> Link to comment https://forums.phpfreaks.com/topic/263374-remove-hyperlinks-from-string/#findComment-1349754 Share on other sites More sharing options...
$php_mysql$ Posted May 30, 2012 Author Share Posted May 30, 2012 Thanks barand will be waiting on it thanks scootstah for the idea :-) Link to comment https://forums.phpfreaks.com/topic/263374-remove-hyperlinks-from-string/#findComment-1349755 Share on other sites More sharing options...
Barand Posted May 30, 2012 Share Posted May 30, 2012 Plan B using if (filter_var($v, FILTER_VALIDATE_URL)) only found http://www.somesite.com/details.php?id=123456 My plan A found http://www.somesite.com/details.php?id=123456 www.somesite.com/details.php?id=123456 somesite.com/details.php?id=123456 Link to comment https://forums.phpfreaks.com/topic/263374-remove-hyperlinks-from-string/#findComment-1349770 Share on other sites More sharing options...
$php_mysql$ Posted May 31, 2012 Author Share Posted May 31, 2012 Plan B using if (filter_var($v, FILTER_VALIDATE_URL)) only found http://www.somesite.com/details.php?id=123456 My plan A found http://www.somesite.com/details.php?id=123456 www.somesite.com/details.php?id=123456 somesite.com/details.php?id=123456 thanks mate but i am unable to get it to work with my existing function that i posted above? Link to comment https://forums.phpfreaks.com/topic/263374-remove-hyperlinks-from-string/#findComment-1349990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.