Forum Moderators: coopster

Message Too Old, No Replies

Cannot output of a function inside a variable...

         

irock

3:21 pm on Apr 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi I want to output the result of the function in a variable but failed. I was wondering if there's anything I did wrong.

function checkos($os) {
if (ereg("Windows XP", $prodrow[4]))
print "checked";
}

$platforms = "Supported platform: ". checkos("Windows XP") .".";

print $platforms;

Turns out this only returns...
---------------------------------
Supported platform:
---------------------------------

Could anyone help on outputing the checkos function?

Thanks in advance!

mavherick

3:36 pm on Apr 24, 2003 (gmt 0)

10+ Year Member



It doesn't work because you have no return statement, try this in your checkos function:

function checkos($os) {
if (ereg("Windows XP", $prodrow[4]))
{
$status = "checked";
} else {
$status = "invalid";
}

return $status;
}

mavherick

irock

3:55 pm on Apr 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm... it still doesn't work.

I have something like this...

function checkos($os) {
$prodrow[4] = "Windows XP, Windows 2000";
if (ereg("Windows XP", $prodrow[4]))
{
$status = "checked";
} else {
$status = "invalid";
}

return $status;
}

$platforms = "Supported platform: ". checkos("Windows XP") .".";

I still get "Supported platform: "
Could it be an error with the $platforms statement?

Thanks again!

toadhall

4:33 pm on Apr 24, 2003 (gmt 0)

10+ Year Member



It should work. Maybe you just need to clear your cache.

BTW, to accept the value where the function is called, this line:

if (ereg("Windows XP", $prodrow[4]))

should be:

if (ereg($os, $prodrow[4]))

...and for a case insensitive search use eregi()

T