0

Hi I am using php system to embed a cgi-script like this

<?php echo system('./cgi-bin/rebol-include.cgi'); ?>

Problem is my cgi-script writes

print "content-type: text/html^/"

so that PHP will show up

"content-type: text/html"

above the html page. 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 ?

1
  • but why u would lik remove it ?:) Commented Dec 8, 2009 at 14:06

3 Answers 3

1

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".

Sign up to request clarification or add additional context in comments.

Comments

1

Instead of printing out content within the script, return it as a string. Then echo will actually do its job. Also can parse whole content with strip_tags() or similiar if wanna get rid of HTML.

Comments

1

Have you tried using virtual() instead of system() ?

virtual() is an Apache-specific function which is similar to in mod_include. It performs an Apache sub-request. It is useful for including CGI scripts or .shtml files, or anything else that you would parse through Apache. Note that for a CGI script, the script must generate valid CGI headers. At the minimum that means it must generate a Content-Type header.

see http://php.net/manual/en/function.virtual.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.