Preg_replace - NULL result?

Here is a small example (download, rename to .php and run it in your shell):

test.txt

Why preg_replacereturns NULL instead of the original string?

\x{2192}matches HTML " →" ("→").

+3
source share
4 answers

From the documentation for preg_replace () :

Return values

preg_replace () returns an array if the subject parameter is an array or string otherwise.

If matches are found, the new object will be returned, otherwise it will be returned unchanged or NULL if an error occurs.

, u . WRONG

: , - . "147 3.2 V6 - GTA (184 )" , .

2: 3 , , , . , 160 ( 32). , , , .

:

'147 3.2 V6 - GTA (184 kW)'
'147 3.2_V6 - GTA_(184_kW)'
+2

, u UTF-8 PCRE. UTF, , .

+2
  • , , , . escape- (, \x32, "")
  • UTF8, escape- \x2192 . : \x21\x92, , utf8_encode utf8_decode
  • - . PHP : : preg_replace(): : UTF-8 0 test.php 7
-1

I believe there is also an error in the Regex expression: ~\x{2192}~u

Try replacing what I have and see if this is for you: /\x{2192}/u

-3
source

Source: https://habr.com/ru/post/1717874/


All Articles