Here's a small example (download, rename to .php and execute it in your shell):
Why does preg_replace
return NULL instead of the original string?
\x{2192}
is the same as HTML "→
" ("→").
Here's a small example (download, rename to .php and execute it in your shell):
Why does preg_replace
return NULL instead of the original string?
\x{2192}
is the same as HTML "→
" ("→").
From the documentation on preg_replace():
Return Values
preg_replace() returns an array if the subject parameter is an array, or a string otherwise.
If matches are found, the new subject will be returned, otherwise subject will be returned unchanged or NULL if an error occurred.
In your pattern, I don't think the u flag is supported. WRONG
Edit: It seems like some kind of encoding issue with the subject. When I erase '147 3.2 V6 - GTA (184 kW)' and manually re-type it everything seems to work.
Edit 2: In the pattern you provided, there are 3 spaces that seem to be giving issues to the regex engine. When I convert them to decimal their value is 160 (as opposed to normal space 32). When I replace those spaces with normal ones it seems to work.
I've replaced the offending spaces with underscores below:
'147 3.2 V6 - GTA (184 kW)' '147 3.2_V6 - GTA_(184_kW)'
I believe there is also a fault in your Regex expression: ~\x{2192}~u
Try replacing what I have and see if that works out for you: /\x{2192}/u
\x32
, then use double quotes "")\x2192
is not correct either. You can do: \x21\x92
to get both bytes into your string, but you may want to look at utf8_encode
and utf8_decode