Thank you, but it doesn't work:
$str = 'test "first string" test "second string longer" end';
$RegExp = '#[" ]{2,}(\w+)[" ]{2,0}#';
$str = preg_replace($RegExp, '%$1%', $str); // Error line
echo $str;
Warning: preg_replace() [function.preg-replace]: Compilation failed: numbers out of order in {} quantifier at offset 21 in C:\...\script.php on line Error line
I'm having hard time with PREG_REPLACE.
I have this string ($str):
test \"first string\" test \"second string longer\" end
I need to have:
%test%first string%test%second string longer%end%
This doesn't work:
echo preg_replace('#(")(.*?)(")#i', '%$2%', stripslashes($str));
Result:
test %first string% test %second string longer% end
Thanks all for help!
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.