Welcome Guest, Not a member yet? Register   Sign In
Backslash not displayed in the string
#1

[eluser]GabrieleMartino[/eluser]
Hello,

i need to print "\( ... \) or $$ ... $$". I tried adding \\ and htmlspecialcharacters(lang (variable_name)); but the \ is not printed in the second \ only in the first.

Any ideas?

Thanks
#2

[eluser]TheFuzzy0ne[/eluser]
In a double-quoted string, a backslash is an escape character, you you need to type TWO backslashes in succession for it to render correctly.
Code:
echo "\\(backslash\\)";

Also, in double-quoted strings, variables are parsed, and since variables begin with a dollar sign, it needs to be escaped in order for it not to be parsed.
Code:
$str = 'Hello';
echo "$str" // Prints "Hello".
echo "\$str"; // Prints "$str".

By using single-quotes, variables won't be parsed, but you will still need to escape backslashes.
Code:
echo '\\$str\\'; // Prints "\$str\".
echo '\\\\$str\\\\'; // Prints "\\$str\\".




Theme © iAndrew 2016 - Forum software by © MyBB