简体   繁体   中英

replacing backslash string in php

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM