cormanaz Posted August 27, 2010 Share Posted August 27, 2010 Good day freaks. I am pulling my hair out trying to figure this out. I am trying to pass patterns for preg_replace through $_GET and then apply them. The object is to highlight certain words in a chunk of text. Say I want to highlight bounded cases of 'foo' in the text. So here's what I'm doing: $string = urldecode($_GET['highlight1']); // $string contains \\bfoo\\b $search = preg_replace('/\\\\b/','b',$string); // $search contains \bfoo\b as I want it to $replace = preg_replace('/\\\\b/','',$string); // $replace contains \foo\ >:-( $pattern = '/'.$search.'/i'; $text = preg_replace($pattern,'<span style="background-color:yellow;">'.$replace.'</span>',$text); The problem is that no matter what I try for the pattern for $replace, it winds up with backslashes around foo. How do I get rid of these? (I should say that I discovered the pattern/replace for the $search string by experimentation and I don't understand why the pattern doesn't pick off all the backslashes in that case--but at least it does what I want). TIA Steve Link to comment https://forums.phpfreaks.com/topic/211876-how-to-get-rid-of-backslashes-passed-through-_get/ Share on other sites More sharing options...
AbraCadaver Posted August 27, 2010 Share Posted August 27, 2010 $string = $_GET['highlight1']; if(get_magic_quotes_gpc()) { $string = stripslashes($string); } Get data is automatically url decoded before the $_GET is populated. Link to comment https://forums.phpfreaks.com/topic/211876-how-to-get-rid-of-backslashes-passed-through-_get/#findComment-1104362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.