Rebol Tutorial
Rebol Tutorial

Reputation: 2754

Problem embedding a cgi within PHP using system

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 ?

Upvotes: 0

Views: 183

Answers (3)

Tom Haigh
Tom Haigh

Reputation: 57815

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

Upvotes: 1

Tomasz Durka
Tomasz Durka

Reputation: 586

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.

Upvotes: 1

ChronoFish
ChronoFish

Reputation: 3707

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

Upvotes: 1

Related Questions