3v4l.org

run code in 300+ PHP versions simultaneously
<?php // note the const declarations -- constants really read-only vars const COMMA = ','; const EMPTY_STR = ""; const NULL_CHAR = "\0"; $delim = '\n'; // note what happens when inserted into doubled-quoted string $data = "1,2,3,$delim,4,5,6,$delim,7,8,9"; echo "\nThe data is:\n\n$data\n\n"; var_dump( EMPTY_STR, NULL_CHAR,strcmp(EMPTY_STR, NULL_CHAR)); // "" != "\0" and "" !== "\0" echo "Is null char empty value? ",empty(NULL_CHAR)? 'true':'false',"\n"; echo "Is zero an empty value? ",empty(0)? 'true':'false',"\n"; $strNumsEtc = str_replace( COMMA, EMPTY_STR, $data); echo "\nResult: $strNumsEtc\n"; $strArr = explode( $delim, $strNumsEtc); var_dump($strArr); $res = preg_split('/(\\|n)/',$strNumsEtc); var($res); foreach ($strArr as $str) { echo $str,PHP_EOL; // echo print both shades of echo: echo multiple vars, print one var plus retval } // must add the PHP_EOL since PHP doesn't automatically do this echo PHP_EOL; foreach ($strArr as $str) { print $str; print PHP_EOL; }
Output for 5.4.0 - 5.4.34
Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /in/dpClJ on line 10
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /in/dpClJ on line 10
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_CONST in /in/dpClJ on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_CONST in /in/dpClJ on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/dpClJ on line 3
Process exited with code 255.

preferences:
227.59 ms | 1395 KiB | 124 Q