3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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(preg_split(/\n/,$strNumsEtc,3)); 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; }
based on jAnf9
Output for 5.4.0 - 5.4.34
Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /in/OYkHj on line 13
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /in/OYkHj on line 13
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_CONST in /in/OYkHj on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_CONST in /in/OYkHj on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/OYkHj on line 3
Process exited with code 255.