Sunday 15 August 2010

php - Dual \ when entering text inside text field -


I have a simple text field where customers can enter their html / php code.

On some servers all are working well, but as soon as I write:

\ to \\

So I want to remove it from such a code, but it does not work: $ text = str_replace ('\', '' , $ Text);

Any ideas? You are probably looking for:

  $ text = Str_replace ('\\\\', '\\', $ text);   

This replaces \ with \ , or:

  $ text = str_replace '\\', '', $ text);   

It changes anything \ .

The reason you need to use \\ (and \\\\ for two slashes) \ Is to avoid, because, by itself, '\' is to avoid closing quotation in order to make your string incomplete. Therefore, you need to avoid \ , by changing it to '\\' .

This difference between the server is likely to be the reason, and you can prevent the code as above, ensuring that this configuration entry has the same value for both servers.

And, after that, you can reflect it with only one call, and will tell you get the exact same result.

No comments:

Post a Comment