concatenating a number with string not parsed in PHP
I have this simple concatenation in my PHP code that concatenates a few
strings together to make an XML request. For some reason, when I
concatenate the customerId with the string chain, it's not parsed. But if
I pass a constant number within single quotes, it's parsed. Here is an
example.
I if I concatenate with a constant number, like this:
$out='<?xml version="1.0"?>';
$out=$out.'<soapenv:Envelope ';
$out=$out.'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ';
$out=$out.'xmlns:v1="http://www.test.com/v1">';
$out=$out.'<soapenv:Header/>';
$out=$out.'<soapenv:Body><v1:loadData><customerNumber>';
$out=$out.'2985634';
$out=$out.'</customerNumber></v1:loadData>';
$out=$out.'</soapenv:Body>';
$out=$out.'</soapenv:Envelope>';
Echoing $out will give me:
<?xml version="1.0"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://www.test.com/v1"><soapenv:Header/><soapenv:Body><v1:loadData><customerNumber>2985634</customerNumber><version>1</version></v1:loadData></soapenv:Body></soapenv:Envelope>
But if I pass a variable instead of a constant number(which is what I
passed from a from by POST method), it wont' be parsed, as shown below:
$custId = $_POST['customerId'];
$out='<?xml version="1.0"?>';
$out=$out.'<soapenv:Envelope ';
$out=$out.'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ';
$out=$out.'xmlns:v1="http://www.test.com/v1">';
$out=$out.'<soapenv:Header/>';
$out=$out.'<soapenv:Body><v1:loadData><customerNumber>';
$out=$out.$custId;
$out=$out.'</customerNumber></v1:loadData>';
$out=$out.'</soapenv:Body>';
$out=$out.'</soapenv:Envelope>';
The output of echo will be:
<?xml version="1.0"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://www.test.com/v1"><soapenv:Header/><soapenv:Body><v1:loadData><customerNumber></customerNumber><version>1</version></v1:loadData></soapenv:Body></soapenv:Envelope>
I tried different ways of concatenation and stringifying the variable, but
none worked :(
No comments:
Post a Comment