Jump to content

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.