0

I'm using PHP environment and I have a problem in displaying data on form of escape characters.

example:

how could i display a double quote " if my string data is \"

same with, how could i display a backslash \ if my string data is \\

2
  • When displaying data on form, you need HTML escaping, not PHP Commented Mar 13, 2013 at 12:55
  • 1
    Im not displaying data on HTML, I raise this question for export to excel purposes. Commented Mar 13, 2013 at 13:08

2 Answers 2

1

To remove \ characters that are used as an escape characters, use the stripslashes function.

david@raston ~ $ cat tmp/test.php
<?php

$raw = 'double slash \\\\ escaped quote \"';
print $raw;
print "\n";
print stripslashes($raw);
?>

david@raston ~ $ php tmp/test.php
double slash \\ escaped quote \"
double slash \ escaped quote "
Sign up to request clarification or add additional context in comments.

Comments

0

Everyone else has covered it and this is all documented here but for the sake of completeness I'd also suggest taking a look at the heredoc notation which can be useful when your data is changing through several contexts (eg. PHP -> HTML/JS -> JS-Regex)

<?php
echo <<<__EOF
It's not great for PHP indentation but often helps readability \ " ' `
__EOF;

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.