[英]Problem embedding a cgi within PHP using system
Hi I am using php system to embed a cgi-script like this 嗨,我正在使用php系统来嵌入这样的cgi脚本
<?php echo system('./cgi-bin/rebol-include.cgi'); ?>
Problem is my cgi-script writes 问题是我的CGI脚本写道
print "content-type: text/html^/"
so that PHP will show up 这样PHP就会出现
"content-type: text/html"
above the html page. html页面上方。 This is an unwanted artefact, what's the optimal way to remove it knowing a whole html page is returned from the cgi to be embedded in php ? 这是不想要的人工制品,知道从cgi返回整个html页并嵌入php时,删除它的最佳方法是什么?
System can be replaced with back ticks "`" and the result of the back tick can be inserted into a substring. 可以用反勾号“`”替换系统,并且可以将反勾号的结果插入子字符串中。
So 所以
<?= substr(`./cgi-bin/rebol-include.cgi`, strlen('content-type: text/html^/')) ?>
This should give you everything after the "content-type". 这应该给您“内容类型”之后的所有内容。
Instead of printing out content within the script, return it as a string. 而不是在脚本中打印出内容,而是将其作为字符串返回。 Then echo will actually do its job. 然后echo实际上会完成其工作。 Also can parse whole content with strip_tags() or similiar if wanna get rid of HTML. 如果想摆脱HTML,也可以使用strip_tags()或类似方法解析整个内容。
Have you tried using virtual() instead of system() ? 您是否尝试过使用virtual()而不是system()?
virtual() is an Apache-specific function which is similar to in mod_include. virtual()是Apache特定的函数,类似于mod_include。 It performs an Apache sub-request. 它执行Apache子请求。 It is useful for including CGI scripts or .shtml files, or anything else that you would parse through Apache. 这对于包含CGI脚本或.shtml文件,或您将通过Apache解析的其他任何文件很有用。 Note that for a CGI script, the script must generate valid CGI headers. 请注意,对于CGI脚本,该脚本必须生成有效的CGI标头。 At the minimum that means it must generate a Content-Type header. 至少这意味着它必须生成一个Content-Type标头。
see http://php.net/manual/en/function.virtual.php 参见http://php.net/manual/en/function.virtual.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.