Php parse explode error

Iโ€™m optimizing my site a bit. Tested the page locally, everything is in order. When I download it and access it live, it smoothly throws a parsing error ... but it works fine locally, as I said.

Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/theriff/www/frvideos.php on line 25 

The code is as follows:

 echo explode('|',$youtube[$i])[2].'<br />'."\r\n"; 

$ youtube [$ i] is a string formed as follows:

 DFHG-LINKYOUTUBE-HJGHJ|french Description|English Description 

The YouTube link is an identifier, so there is no '|' the symbol in it is for sure, and it is read from a text file that I write manually myself, so I'm sure of the record.

Does anyone know why it works fine on the local (EasyPhp Developper), but not on the remote server?

+5
source share
2 answers
 $results = explode('|',$youtube[$i]); echo $results[2].'<br />'."\r\n"; 

The PHP version is not the same, so there is no array chain on the remote server.

+3
source

Old (<5.4) In PHP versions, arrays of function return values โ€‹โ€‹cannot be directly dereferenced, you should temporarily save the result in a variable:

 $exploded = explode('|',$youtube[$i]); echo $exploded[2].'<br />'."\r\n"; 
+2
source

Source: https://habr.com/ru/post/1201013/


All Articles