regex - preg_replace to find and replace a string in php -
this question exact duplicate of:
using preg_replace find symbols + or - contains inside of string, if found means replace string double quote("") or single quote('').
for eg:
1.if sometext+sometext replace "sometext+sometext"
2.if sometext-sometext replace "sometext-sometext"
try following code:
echo preg_replace('/\b\w+[+-]\w+\b/', '"$0"', $text);
Comments
Post a Comment