1

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.

3
  • I am seeing the same as in "I need to replace x with x", seems the editor ate a few chars?. edit seems you corrected it. Commented Sep 22, 2011 at 23:11
  • 1
    Am I missing something, or are you trying to replace a string with the exact same string? A good way to do this is $result = '\bhello\b';. Magic. Commented Sep 22, 2011 at 23:13
  • fixed it ... replace backslash b with backslash backslash b Commented Sep 22, 2011 at 23:34

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.