Jump to content


Photo

parse error


  • Please log in to reply
2 replies to this topic

#1 pneudralics

pneudralics
  • Members
  • PipPipPip
  • Advanced Member
  • 241 posts

Posted 12 March 2006 - 08:13 PM

Got this from the random pic tutorial here. I'm getting Parse error: parse error, unexpected '\"', expecting ',' or ';'

The following is line 23:
echo "<img src="".$file_dir."/".$arry_txt[rand(0, sizeof($arry_txt) -1)]."">";

So what went wrong? I'm still really new at php. Tried taking out the / and quotes, but nothing.


<?
// #### RANDOM PIC #########################################

    $thumbstring = '';
    $file_dir="pics/a10";    // DIRECTORY WITH THE PICS

    $f_type="tm.jpg";    // FILE EXTENSION YOU WISH TO DISPLAY

    $dir=opendir($file_dir);
    while ($file=readdir($dir))
    {
        if ($file != "." && $file != "..")
        {
            $extension=substr($file,-6);    // THIS DIGIT MUST MATCH THE NUMBER OF CHARACTERS SPECIFIED IN THE FILE EXTENSION ABOVE
            if($extension == $f_type)
            {
                $thumbstring .= "$file|";
            }
        }
    }
    srand((double)microtime()*1000000);
    $arry_txt = explode("|" , $thumbstring);
    echo "<img src="".$file_dir."/".$arry_txt[rand(0, sizeof($arry_txt) -1)]."">";


// #### END RANDOM PIC #########################################
?>


#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 12 March 2006 - 08:44 PM

Whatever character you start the string with, single or double quotes, that same character must be escaped if it's contained within that string.

For more info, click the link below and find the answer to "Q: Is there another way of getting around escaping quotes all the time?"

[a href=\"http://www.phpfreaks.com/forums/index.php?s=&showtopic=31047&view=findpost&p=153359\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=153359[/a]



#3 pneudralics

pneudralics
  • Members
  • PipPipPip
  • Advanced Member
  • 241 posts

Posted 12 March 2006 - 09:02 PM

What do I need to add in if I didn't want mike.jpg to be displayed as a random image?

Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users