我需要将变量从txt文件加载到特定的XML元素。但有些我怎么不能恰当地回应。
这是我的txt文件输出(userlist.txt(abcxyzLMN-
下面是代码。
<?php
foreach(file('userlist.txt') as $line) {
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Getid xmlns="http://test_xyz/">
<uname>'. $line. '</uname>
<org>Test_GRP</org>
</Getid>
</soap:Body>
</soap:Envelope>';
echo $xml_post_string;
}
?>
下面是输出
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Getid xmlns="http://test_xyz/">
<uname>abc
</uname>
<org>Test_GRP</org>
</Getid>
</soap:Body>
</soap:Envelope>
uname元素不是内联的,不管我怎么做。
您需要标记file()
以忽略每行末尾的新行。。。
file('userlist.txt', FILE_IGNORE_NEW_LINES)