Preg match æøå
Hej Eksperter!Jeg har en funktion som finder nogle key words ud fra en sætning. Mit problem er at skulle keywords den finder være "århus, københavn" returnere funktionen "rhus, kbenhavn" - altså æøå virker ikke..
Nogle forslag til hvordan jeg kan få den til at virke med æ ø å?
På forhånd tak
class keyWords {
public function extractKeywords($content,$minLenght,$headingWeight,$linksWeight,$numberOfKeywords){
// minimum lenght a keyword must have
$keywordArray = array();
//Count the link keywords
$links = array();
preg_match_all('#<a.*?>(.*?)</a.*?>#s',$content,$links);
foreach($links[1] as $key =>$value){
$keywords = explode(' ',strip_tags($value));
foreach($keywords as $id => $keyword){
// Get the alpha numeric value for the keyword
$keyword = preg_replace('/[^[:alpha:]]/', '', $keyword);
if(strlen($keyword) >= $minLenght){
if(!array_key_exists($keyword,$keywordArray)){
$keywordArray[$keyword] = $linksWeight;
}
else{
$keywordArray[$keyword] += $linksWeight;
}
}
}
}
//Count the heading keywords
$headings = array();
preg_match_all('#<h(.*?)>(.*?)</h.*?>#s',$content,$headings);
foreach($headings[2] as $key =>$value){
$keywords = explode(' ',strip_tags($value));
foreach($keywords as $id => $keyword){
// Get the alpha numeric value for the keyword
$keyword = preg_replace('/[^[:alpha:]]/', '', $keyword);
if(strlen($keyword) >= $minLenght){
$divider = (int)$headings[1][$key];
if($headingNumber == 0)$headingNumber = 1;
if(!array_key_exists($keyword,$keywordArray)){
$keywordArray[$keyword] = $headingWeight/$headingNumber;
}
else{
$keywordArray[$keyword] += $headingWeight/$headingNumber;
}
}
}
}
// Count the text keywords including the heading and link texts!
// Meaning these are counted double once with a rating of 1 and once with the rating set for them!
$text = str_ireplace(array('/',"\n",'<br />','<br/>'),' ',$content);
$text = strip_tags($text);
$keywords = explode(' ',$text);
foreach($keywords as $key => $keyword){
// Get the alpha numeric value for the keyword
$keyword = preg_replace('/[^[:alpha:]]/', '', $keyword);
if(strlen($keyword) >= $minLenght){
if(!array_key_exists($keyword,$keywordArray)){
$keywordArray[$keyword] = 1;
}
else{
$keywordArray[$keyword] += 1;
}
}
}
// Sort the keywords
arsort($keywordArray);
// Take only the number of keywords set in the config
$keywordArray = array_slice($keywordArray,0,$numberOfKeywords);
return strtolower(implode(', ',array_keys($keywordArray)));
}
}
