Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Splitting long query string across multiple lines

Tags:

string

php

I've got a long string which I want to split accross multiple lines so it's easier to read. but I'm not sure what the syntax is

$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>");

Can someone help me out please?

like image 878
iamjonesy Avatar asked Sep 15 '10 12:09

iamjonesy


People also ask

How can I split a string into two strings in PHP?

explode() is a built in function in PHP used to split a string in different strings. The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.

How can I split sentences into words in PHP?

Use explode() or preg_split() function to split the string in php with given delimiter. PHP | explode() Function: The explode() function is an inbuilt function in PHP which is used to split a string in different strings.

How do I split a line in a string?

The splitlines() method splits a string into a list. The splitting is done at line breaks.

What is splitting in PHP?

Definition and Usage. The str_split() function splits a string into an array.


2 Answers

just split it into multiple strings and concatenate them, like this:

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

or use heredoc:

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

$xml = array('sXML' => $sXML);
like image 102
Raoul Duke Avatar answered Sep 30 '22 15:09

Raoul Duke


If it doesn't matter if linebreaks are added, you can simply write:

<?php
$xml = array('sXML' => "<abc>
<def>Asdfg</def>
</abc>";
?>
like image 35
matsolof Avatar answered Sep 30 '22 17:09

matsolof