Jump to content
New Reality: Ads For Members ×

parse error


pneudralics

Recommended Posts

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.


[code]<?
// #### 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 #########################################
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/4779-parse-error/
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/4779-parse-error/#findComment-16777
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.