开发者

\r help in PHP -- interpretation error

开发者 https://www.devze.com 2023-03-18 08:19 出处:网络
I am writing a code in PHP and line is as follows $xml_output .= \"\\t\\t\\t<\\report-paper_metadata>\\n\"开发者_C百科;

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号