Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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 Echo_Php_Variables_Echo - Fatal编程技术网

带有系统命令的PHP Echo

带有系统命令的PHP Echo,php,variables,echo,Php,Variables,Echo,我需要在php系统命令中调用一个变量($id)。我正在自动执行solr curl delete命令,该命令使用静态id,但我需要回显$id,以便它删除正确的文档 代码是: <?php echo '<pre>'; $last_line = system('curl http://localhost:8983/solr/imagedb/update?commit=true --data \'<delete><query>id\:<?php echo

我需要在php系统命令中调用一个变量($id)。我正在自动执行solr curl delete命令,该命令使用静态id,但我需要回显$id,以便它删除正确的文档

代码是:

<?php
echo '<pre>';

$last_line = system('curl http://localhost:8983/solr/imagedb/update?commit=true --data \'<delete><query>id\:<?php echo $id; ?></query></delete>\' -H \'Content-type:text/xml; charset=utf-8\'', $retval);

// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>

删除
php
标记,并在
系统
调用中用单引号括起变量。现在,您的
变量
以及php标记将作为字符串传递

因此,请更新这一行:

$last_line = system('curl http://localhost:8983/solr/imagedb/update?commit=true --data \'<delete><query>id\:'.$id.'</query></delete>\' -H \'Content-type:text/xml; charset=utf-8\'', $retval);
$last_line=系统('curlhttp://localhost:8983/solr/imagedb/update?commit=true --数据“id\:\”-H“Content-type:text/xml;charset=utf-8\”,$retval);
致:

$last_line=系统('curlhttp://localhost:8983/solr/imagedb/update?commit=true --数据“id\:”.$id.\”-H“内容类型:text/xml;字符集=utf-8\'”,$retval);
不能在字符串中使用
。这仅在退出PHP执行模式时有效。使用字符串连接

$last_line=系统('curlhttp://localhost:8983/solr/imagedb/update?commit=true --数据'id\:'.$id.'\'-H'Content-type:text/xml;charset=utf-8\''.$retval);

我们在这里看不到定义了
$id
,因此我们可能无法帮助您解释为什么
$id
为空。宾果!有趣的是,你的答案和zejur的答案在语法上的细微差别造成了不同。”$身份证。”有效,但“$id”无效。谢谢你们,没什么区别。忽略
周围的空格。
$last_line = system('curl http://localhost:8983/solr/imagedb/update?commit=true --data \'<delete><query>id\:'.$id.'</query></delete>\' -H \'Content-type:text/xml; charset=utf-8\'', $retval);
$last_line = system('curl http://localhost:8983/solr/imagedb/update?commit=true --data \'<delete><query>id\:' . $id . '</query></delete>\' -H \'Content-type:text/xml; charset=utf-8\'', $retval);