\r help in PHP -- interpretation error
I am writing a code in PHP and line is as follows
$xml_output .= "\t\t\t<\report-paper_metadata>\n"开发者_C百科;
As u can see that i am trying 2 output
<\report-paper_metadata>
But PHP is reading it as \r
feed ..
<eport-paper_metadata>
I dont want to declare using a variable and use it..
any suggestion on how overcome this??
Any questions plzzz comment..
\r
is a special character, just like \n
. Use \\r
instead (double slash).
Escape the slash:
$xml_output .= "\t\t\t<\\report-paper_metadata>\n";
You should be able to escape it, e.g. \\r
.
If you were not relying on other special characters, you could also use single quotes ('
) which treats each character literally in the string.
Special characters are interpreted in double quotes ("
) only (and HEREDOC and NOWDOC).
use double \
like \\
and it will work :)
Escape the \r
with an extra \
:
$xml_output .= "\t\t\t<\\report-paper_metadata>\n";
Or better separate formatting and data:
$xml_output .= "\t\t\t".'<\report-paper_metadata>'."\n";
Even if not a nice solution but just to be exhaustive keeping double quotes you also can use concatenation of string just like that: $xml_output .= "\t\t\t".'<\report-paper_metadata>'."\n";
I admit it's not nice at all ;) @alex answers is the most complete one imho
精彩评论