string error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpBrandNew
Forum Commoner
Posts: 36
Joined: Thu Sep 02, 2010 12:51 am

string error

Post by phpBrandNew »

I have the following code and I got the following error :

<?php
$myswfarray("A.swf", "B.swf", "C.swf");
$randomswf = array_rand(array_flip($myswfarray), 1);

echo "show $randomswf ";
?>

Fatal error: Function name must be a string in C:\xampp\htdocs\loadswf.php on line 2

Could someone point out where should I change for the function name and how ?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: string error

Post by McInfo »

PHP thinks "$myswfarray" is a variable that should contain a function name because it is followed by "(". Because $myswfarray is not set, it is not a string, hence the error.

The real problem is that an assignment operator is missing.

Code: Select all

$myswf = array("A.swf", "B.swf", "C.swf");
phpBrandNew
Forum Commoner
Posts: 36
Joined: Thu Sep 02, 2010 12:51 am

Re: string error

Post by phpBrandNew »

I change as following, I have the message show swf in random manner. I put the swf with php file, but swf is not loaded, please advise.

<?php
$myswf=array("A.swf", "B.swf", "C.swf");
$randomswf = array_rand(array_flip($myswf), 1);

echo "show $randomswf ";
?>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: string error

Post by McInfo »

The Flash is not loaded because the output from your script (a string, "show A.swf ") has no meaning to any of the actors involved in transporting data from the server to the user. It is simply a string of characters.

I am not sure what you wish to happen, but perhaps it would be suitable to replace

Code: Select all

echo "show $randomswf ";
with

Code: Select all

header('Content-Type: application/x-shockwave-flash');
readfile($randomswf);
phpBrandNew
Forum Commoner
Posts: 36
Joined: Thu Sep 02, 2010 12:51 am

Re: string error

Post by phpBrandNew »

OK, it is just what I want. Thanks.
Post Reply