PDA

View Full Version : converting a 10 line cgi to php.


edge
3rd June 2006, 00:48
Could some CGI, PHP expert please show me how this small CGI script should look like in PHP?

The CGI script:

#!/usr/bin/perl
use CGI;

my $cgi = CGI->new();
my @param = $cgi->param();

print"Content-type: text/html\n\n";
for(@param)
{
my @arr = $cgi->param($_);
print"$_:".join(':',@arr)."<br>";
}


All I got till now in PHP is:

<?php

echo "Content-type: text/html\n\n";

?>



Please help.. I'm lost...

sjau
3rd June 2006, 10:49
You want to loop through an array?
I don't know Perl... but PHP ^^

falko
3rd June 2006, 14:35
I'm no Perl expert either... What does the CGI script do?

edge
3rd June 2006, 18:16
I'm no Perl expert either... What does the CGI script do?

It's some code that will dump/show a variable..

I've now recoded it in the language I know best.. Coldfusion :-)
No need for the PHP code anymore.

sjau
3rd June 2006, 18:20
For showing a variable in PHP it's straight-forward:


<? echo $var; ?>

falko
3rd June 2006, 23:02
If it's an array, then use
<?php
print_r($arr);
?>

sjau
3rd June 2006, 23:40
or a foreach ^^


foreach($arr as $key => $val) {
echo "Key: $key / Val: $val";
}

or without key:

foreach($arr as $val) {
echo "Val: $val";
}