i am using PHP scripts to implement this…
$keyword=array('local news','art','local','world','tech','entertainment','news','tech','top stories','in the news','front page','bbc news','week in a glance','week in pictures','top stories');
//$keyword has predefined array of strings
$all_meta_tags=get_meta_tags("http://abcnews.go.com/");
$array=$all_meta_tags['keywords'];//store 'keyword' attribute values in $keyword_meta
Now i have to match contents of $array with $keyword…..the results should give me matched items of $array which are present in $keyword
any help plz…?
can array matching/intersection be done case insensitively??
i mean if
$keyword=array(‘local news’);
$array = ‘Local News, International News’;
var_dump(array_intersect(preg_split(‘/,\s*/’, $array), $keyword));
then it won’t match ‘Local News’…can you tel me hw to do it if it is possible??
CodePad.
get_meta_tags()just returns the keywords as a string, so we need to split it into an array. We take into account people adding spaces, newlines or tabs after the,.You could also skip the regex, and explode on
,and then usearray_map('trim', $array).Without doing this, you run the risk of
"art"and" art"not matching.Update
If you don’t mind the resulting arrays being lowercase, you could use
array_map('strtolower', $array)on both arrays before usingarray_intersect().Otherwise, this will do it…
$matcheswill have keywords in both arrays case insensitively.If you have multibyte strings, use
mb_strtolower()or equivalent.