开发者

replacing backslash string in php

开发者 https://www.devze.com 2023-04-07 01:25 出处:网络
I need to replace \\b with \\\\b in php in order to insert into mysql table. Therefore \\bhello\\b becomes \\\\bhello\\\\b then inserted into mysql where it is converted back to \\bhello\\b开发者_JS

I need to replace \b with \\b in php in order to insert into mysql table.

Therefore \bhello\b becomes \\bhello\\b then inserted into mysql where it is converted back to \bhello\b开发者_JS百科.

But I can't seem to figure out how. Tried preg_replace and str_replace and I always end up with an error or what I started with.


Sounds like you need to use the correct escaping mechanism for your database.

For the record, this is definitely not addslashes().

If using mysql_*(), then use mysql_real_escape_string().

If using PDO, use bound parameters with prepared statements.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号