preg_match_all
| From: | Floris | Date: | Tue, 23 Sep 2003 18:00:06 +0000 |
| Subject: | preg_match_all | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-163611@lists.php.net to get a copy of this message | ||
hi,
I have this piece of code. but the problem is that he also links parts of
words (like: credits) and i wnat only standalone words (like: edit)
Does someone have i idea to correct this piece of code?
Floris
----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------
function link_search($search_words,$string,$id)
{
$word_no=0;
foreach($search_words as $search_word)
{
$regex1 = ">[^<]*(";
$regex2 = ")[^<]*<";
preg_match_all("/".$regex1.$search_word.$regex2."/i", $string, $matches,
PREG_PATTERN_ORDER);
foreach($matches[0] as $match)
{
preg_match("/$search_word/i", $match, $out);
$case_sensitive_search_word = $out[0];
$chan = "<a href='woordenboek.php?id=$id&woord=$case_sensitive_search_word'
target='_blank'>$case_sensitive_search_word</a>";
$newtext = str_replace($case_sensitive_search_word, $chan, $match);
$string = str_replace($match, $newtext, $string);
}
$word_no++;
}
return $string;
}