I am being “thick this morning” so please excuse this simple question – I have an array of keywords e.g. array('keyword1','keyword2'....) and I have a string of text – (bit like a blog content in length i.e. not just a few words but may be 200-800 words) what is the best way to search the string for the keywords and replace them with an href link. So in the text ‘keyword 1’ (as plain text) will become <a href='apage'>keyword1</a> and so on.
See said was being thick this am.
Thanks in adavance.
Typical
preg_replacecase:See it in action.
Now the above doesn’t do a very “smart” replace in the sense that the
hrefis not a function of the matched keyword, while in practice you will probably want to do that. Look intopreg_replace_callbackfor more flexibility here, or edit the question and provide more information regarding your goal.