How to replace a backslash character in a string « Kevin Pajak – Interactive Web Developer/Designer – BLOG

How to replace a backslash character in a string

February 12th, 2010

Ah, so often it’s the little things eh…

PROBLEM: I needed to find a way to “re-process” text a user enters for a live chat client I’m working on (in which I prevented MySQL database injections via the mysqli_real_escape_string function). The problem of course is that the text the user enters nicely protects you from a MySQL database injection, BUT the text then comes back full of backslash (\) characters (not too cool looking huh). So, to remove these, you can use the following code (here, I use the PHP str_replace function:

// Convert escaped characters back to regular text
$string = str_replace("\\", "", $string);

Thanks to Geoff Muldoon for this one!:
How to replace a backslash character in a string?

Tags: , ,

One Response to “How to replace a backslash character in a string”

  1. admin says:

    Further reading:

    How To Clean Special Characters From PHP String
    http://www.bala-krishna.com/how-to-clean-special-characters-from-php-string/

    Special ASCII HTML Character Codes
    http://www.yellowpipe.com/yis/tools/ASCII-HTML-Characters/index.php

Leave a Reply