dechamp Posted May 21, 2010 Share Posted May 21, 2010 I'm not understanding what I'm doing wrong and I'm really tired which is my first problem. Solve this for me please! $input = "why won't you change my word. @@origionalWord@@"; $q = "@@{1}[[:word:]]*@@{1}"; $input2 = str_replace($q, 'replacementWord', $input); This is not changing it to "why won't you change my word. replacementWord I've used an regexp gen to verify my work and it's still not working. I tried a ton of different variations. (@@{1}[[:word:]]*@@{1}) (@@){1}[[:word:]]*(@@){1} ((@@){1}[[:word:]]*(@@){1}) and so on. also with ^ and $ Quote Link to comment Share on other sites More sharing options...
cags Posted May 21, 2010 Share Posted May 21, 2010 Firstly str_replace doesn't support complex matching (i.e. Regular Expressions), it only matches literal strings. Secondly the syntax you are using there looks very much like POSIX, ideally you should be using PCRE syntax with the preg_ functions such as preg_match. To replace literal '@@originalWord@@' $output = str_replace('@@originalWord@@', 'replacementWord', $intput; To replace any word between double @ signs $output = preg_replace('#@@[a-z]+@@#i', 'replacementWord', $input); Quote Link to comment Share on other sites More sharing options...
ignace Posted May 21, 2010 Share Posted May 21, 2010 Before shooting yourself, read up on Regex and PHP Regex functions. str_replace() is not one of 'em. $text = 'why won\'t you change my word. @@origionalWord@@'; echo preg_replace('/@@([a-z])+@@/i', 'replacementWord', $text); Edit: meh Quote Link to comment Share on other sites More sharing options...
dechamp Posted May 21, 2010 Author Share Posted May 21, 2010 Wow and this is why working exhausted is a bad idea, I started off with preg_match and throughout testing totally forget that I had tried using str_repace. grrrrr well thank you both for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.