Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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
post参数/simplexml的php问题_Php_Simplexml - Fatal编程技术网

post参数/simplexml的php问题

post参数/simplexml的php问题,php,simplexml,Php,Simplexml,我想使用给定的id访问xml的某个节点,该id是从post参数中获得的,如下所示: $id = $_POST['id']; $xml->content[$id]; 不幸的是,它不工作-返回空。似乎是因为$id可能是字符串类型,而不是整数。 我试图将其转换为: $id = int $id; 这给了我这个错误: syntax error, unexpected T_VARIABLE 有没有办法解决这个问题? 谢谢您应该使用 $id = (int) $id; 而不是$id=int$id

我想使用给定的id访问xml的某个节点,该id是从post参数中获得的,如下所示:

$id = $_POST['id'];
$xml->content[$id];
不幸的是,它不工作-返回空。似乎是因为$id可能是字符串类型,而不是整数。 我试图将其转换为:

$id = int $id;
这给了我这个错误:

syntax error, unexpected T_VARIABLE
有没有办法解决这个问题? 谢谢

您应该使用

$id = (int) $id;
而不是$id=int$id

您应该使用

$id = (int) $id;

而不是$id=int$id

在PHP中使用
(int)$str
intval($str)
执行类型转换:

$id = (int)$id;


在PHP中使用
(int)$str
intval($str)
执行类型转换:

$id = (int)$id;