Forum Moderators: coopster
I'm trying to find a way to ignore punctuation marks and case on the way in but maintain it on the way out.
function bold_keyword($text)
{
$lines = file('custom/seo/keywords');
foreach ($lines as $line)
{
$line = trim($line);
$text = preg_replace('[ '.$line.' ]', ' <strong>'.$line.'</strong> ', $text);
}
return $text;
}
thanks rob, that's pretty close to what i'm looking for.
the only problem is that it replaces it with the case from the list/array.
i want it to just add the <strong> tags and keep the original format.
it should read the list, if it finds the word add <strong> tags.
my original code above makes it so i have to add case variants like the following otherwise it will not hit everything.
Hi Rob
hi rob
Hi rob
hi Rob
your code below eliminates the case variants but replaces it with whatever is in the file.
Hi Rob in the file list will force hi rob to Hi Rob in the returned text.
function bold_keyword($text)
{
$lines = file('custom/seo/keywords.txt');
foreach ($lines as $line)
{
$line = trim($line);
$text = preg_replace("/$line/i", "<strong> $line </strong>", $text);
}
return $text;
}
i hope the above made sense and thanks again for your replies!
OOOOH i just saw what you're trying to do. gimme a minute i'll try to figure it out.
Edit2:
The first code I sent should have worked.
Use \\1 (the number one) in the replace string (instead of $line). That uses a backreference to see what matched.. it should work:
preg_replace("/$line/i", "<strong>\\1</strong>", $string);