1

So I have the following function on my code:

/* returns a random string */
function randStr($length = 32, $chars = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ!@#$%&*()_-+=") {
//function randStr($length, $chars) {
    $validCharNumber = strlen($chars);
    for ($i = 0; $i < $length; $i++) {
        $str .= $chars[rand(0, $validCharNumber - 1)];
    }
    return $str;
}

it was working ok on my local server and some other development server that we used. But on the final server, I keep getting the following message: Parse error: syntax error, unexpected '"'

I searched on google but I couldnt get precise results because I can't use quotes to be more accurate when I'm searching about quotes.

I'm also getting the same error message on this block of code

"last_update" => Array("display" => "return toDate('$1', 'd/m/Y H:i:s');")

Where's the error? Did I miss any kind of configuration for double quotes or something?

4

2 回答 2

3

It's php version issue. You could check your code for php versions compatibilities with online tools which allow to run code on different versions.

For example: http://3v4l.org/60NfG

Deal in '$' inside double quoted string in function argument.

http://3v4l.org/lvm9I

于 2013-11-06T07:56:04.063 回答
0

I only got this error:

Notice: Undefined variable: str in D:\wamp\www\index.php on line 7

Fixed it by adding $str =''; before for loop. Everything else works fine.

My PHP Version is 5.4.12

于 2013-11-06T08:02:30.570 回答