rebajas Posted March 1, 2007 Share Posted March 1, 2007 Hiya, I have a preg_replace which matches a string with non alphanumeric characters either side (i.e not the middle of a word). The problem is, when I replace this with the desired replacement it replaces the non AN chars as well! See code: $linkedKeywords = explode("|", $data[7]); $i = 0; foreach ($linkedKeywords As $val) { $replaceWith = "<a href=\"/search.php?keywordSearch=".urlencode($val)."\">".$val."</a>"; $body = preg_replace("/\W".$linkedKeywords[$i]."\W/", $replaceWith, $body, 1); $i++; } Is there an efficient way to do what I want to do, like set the non alpha numeric characters as delimiters? If I haven't been clear then obviously I'd love to clarify these details. T. Link to comment https://forums.phpfreaks.com/topic/40714-preg_replace-problem-matching-a-string-with-non-alphanumeric-either-side/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.