PHP:跨多行拆分长查询字符串

时间:2010-09-15 12:57:17

标签: php string

我有一个很长的字符串,我希望将其拆分为多行,以便更容易阅读。但我不确定语法是什么

$xml = array('sXML' =>"<queryxml><entity>Ticket</entity><query><field>Status<expression op=\"$condition1\">$complete</expression></field><condition operator=\"AND\"><field>AccountID<expression op=\"equals\">$userid</expression></field></condition><condition operator=\"AND\"><condition><field>QueueID<expression op=\"NotEqual\">$routine</expression></field></condition><condition operator=\"OR\"><field>QueueID<expression op=\"NotEqual\">$recurring</expression></field></condition><condition operator=\"OR\"><field>QueueID<expression op=\"NotEqual\">$clientmanagement</expression></field></condition></condition></query></queryxml>");

有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:15)

将它分成多个字符串并连接它们,如下所示:

$xml = array('sXML' => "lorem" .
 "ipsum" .
 "dolor");

或使用heredoc

$sXML = <<<XML
your text
goes here
XML;

$xml = array('sXML' => $sXML);

答案 1 :(得分:13)

如果添加换行符无关紧要,您只需写下:

<?php
$xml = array('sXML' => "<abc>
<def>Asdfg</def>
</abc>";
?>