Forum Moderators: coopster
I want a server side script which can covert the specified keywords to hyperlinks for one of my existing websites. Any script which can work as a censor/replace function should fit the bill, but I could not find any on google as well. Perhaps I am using the wrong keywords in my search. Can anyone recommend or give a clue to any such script.
Thanks in advance.
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "rw");
$page_text=fread($handle, filesize($filename));
//define keyword array
$keywords=array("keyword1","keyword2", etc...);
//define replacements for keyword array
$keywords_href=array("<A HREF=\"http://...\">keyword1<\/A>","<A HREF=\"http://...\">keyword2<\/A>", etc...).
//replace keywords with href links
$page_text_mod=str_replace($keywords,$keywords_href,$page_text);
fwrite($handle,$page_text_mod);
fclose($handle);
of course, you will have to be careful that none of your keywords are part of the html markup.
And no, I cannot suggest a keyword link script off the top of my head :)