A
A
Alexander2016-03-03 23:34:26
PHP
Alexander, 2016-03-03 23:34:26

MySQL REGEXP. How to escape the "[" character?

Friends, good night.
Tell me, please, what template can be used to escape a string? so that it can insert into mysql-query SELECT ....... WHERE title REGEXP '".$query."' ... Now an error is thrown due to the character "[".. But I can't escape it in any way.. I try like this: Please tell me the correct shielding .. I would be very grateful.
$query = "[hjybrb";
str_replace("[", "\[", $query)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Tikhomirov, 2016-03-04
@up_sweep

You were only a minute away from the solution: for some historical reason, there should be two slashes :/
str_replace ('[', '\\[', $query)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question