HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   converting a 10 line cgi to php. (http://www.howtoforge.com/forums/showthread.php?t=4671)

edge 2nd June 2006 23:48

converting a 10 line cgi to php.
 
Could some CGI, PHP expert please show me how this small CGI script should look like in PHP?

The CGI script:
Code:

#!/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:
Code:

<?php

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

?>


Please help.. I'm lost...

sjau 3rd June 2006 09:49

You want to loop through an array?
I don't know Perl... but PHP ^^

falko 3rd June 2006 13:35

I'm no Perl expert either... What does the CGI script do?

edge 3rd June 2006 17:16

Quote:

Originally Posted by falko
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 17:20

For showing a variable in PHP it's straight-forward:

Quote:

<? echo $var; ?>

falko 3rd June 2006 22:02

If it's an array, then use
PHP Code:

<?php
print_r
($arr);
?>


sjau 3rd June 2006 22:40

or a foreach ^^

Quote:

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

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


All times are GMT +2. The time now is 14:30.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.