Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将PHP中的XML解析为变量_Php_Xml - Fatal编程技术网

将PHP中的XML解析为变量

将PHP中的XML解析为变量,php,xml,Php,Xml,我制作了一个PHP脚本,需要接收以下XML: <contact_email>people@example.com</contact_email> <contact_password>hash_in_sha256</contact_password> 剧本: $jsonBody = file_get_contents("php://input"); $jsonBody = json_decode($jsonBody); $contact_emai

我制作了一个PHP脚本,需要接收以下XML:

<contact_email>people@example.com</contact_email>
<contact_password>hash_in_sha256</contact_password>
剧本:

$jsonBody = file_get_contents("php://input");
$jsonBody = json_decode($jsonBody);

$contact_email = $jsonBody->contact_email;
$contact_password = $jsonBody->contact_password;

但我该怎么做才能拥有“people@example.com如Sahil Gulati所说,使用
simplexml\u load\u string
,只要确保您拥有有效的XML,就应该只有一个顶级节点,例如:

$input = "<contact><contact_email>people@example.com</contact_email><contact_password>hash_in_sha256</contact_password></contact>";

$xml = simplexml_load_string($input);

echo $xml->contact_email;
echo $xml->contact_password;
$input=”people@example.comhash_in_sha256";
$xml=simplexml\u load\u字符串($input);
echo$xml->contact_email;
echo$xml->contact_密码;

正如Sahil Gulati所说,使用
simplexml\u load\u string
,只要确保您有有效的xml,应该只有一个顶级节点,例如:

$input = "<contact><contact_email>people@example.com</contact_email><contact_password>hash_in_sha256</contact_password></contact>";

$xml = simplexml_load_string($input);

echo $xml->contact_email;
echo $xml->contact_password;
$input=”people@example.comhash_in_sha256";
$xml=simplexml\u load\u字符串($input);
echo$xml->contact_email;
echo$xml->contact_密码;

try
simplexml\u load\u string
。Sahil Gulati:不工作try
simplexml\u load\u string的可能重复项的可能重复项
。Sahil Gulati:不工作try
simplexml\u load\u string的可能重复项的可能重复项