0

I try to match this specific string " et " that contains both whitespaces on each side of the "et" word.

In this simplified code:

$in = "Retour et échange"
$search = array(" et ");
$replace = array("");
$return = preg_replace($search, $replace, $in);

I tried all of these options:

"[ et ]"
"[\set\s]"
"[\s(et)\s]"
" et "
"\set\s"
"\s(et)\s"
"\s[et]\s"

None of them is working!

I would like to have this result:

"Retour échange"

3 Answers 3

1

The $search array must be an array of patterns, not an array of strings, add delimiters:

$search = array("/ et /");
//        here __^  __^
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of preg_replace() you could use str_replace(). $in = "Retour et échange"; $search = " et "; $replace = " "; $return = str_replace($search, $replace, $in);

Comments

0

I finaly found the ridiculous problem. I was already removing single whitespace in another array value.

These are working well

"/ et /"
"[ et ]"

Thank you everybody!

1 Comment

That's exactly what I said. It will be nice to accept my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.