3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "HD Alcoa Earnings Soar; Outlook Stays Upbeat BY By James R. Hagerty and Matthew Day PD 12 July 2011 LP Alcoa Inc.'s profit more than doubled in the second quarter. The giant aluminum producer managed to meet analysts' forecasts. However, profits wereless than expected TD Licence this article via our website: http://example.com"; function headerSplit($input) { static $delimsExpr = '/^(HD|BY|PD|LP|TD)/m'; static $whiteExpr = '/\s+/'; $parts = preg_split($delimsExpr, $input, -1, PREG_SPLIT_DELIM_CAPTURE); $result = array(); $i = 0; $l = count($parts); while ($i < $l) { $result[$parts[$i++]] = preg_replace($whiteExpr, ' ', trim($parts[$i++])); } return $result; } var_dump(headerSplit($string));
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Undefined array key 11 in /in/8JZnV on line 30 Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/8JZnV on line 30 array(6) { [""]=> string(2) "HD" [" Alcoa Earnings Soar; Outlook Stays Upbeat "]=> string(2) "BY" [" By James R. Hagerty and Matthew Day "]=> string(2) "PD" [" 12 July 2011 "]=> string(2) "LP" [" Alcoa Inc.'s profit more than doubled in the second quarter. The giant aluminum producer managed to meet analysts' forecasts. However, profits wereless than expected "]=> string(2) "TD" [" Licence this article via our website: http://example.com"]=> string(0) "" }
Output for 8.0.0 - 8.0.30
Warning: Undefined array key 11 in /in/8JZnV on line 30 array(6) { [""]=> string(2) "HD" [" Alcoa Earnings Soar; Outlook Stays Upbeat "]=> string(2) "BY" [" By James R. Hagerty and Matthew Day "]=> string(2) "PD" [" 12 July 2011 "]=> string(2) "LP" [" Alcoa Inc.'s profit more than doubled in the second quarter. The giant aluminum producer managed to meet analysts' forecasts. However, profits wereless than expected "]=> string(2) "TD" [" Licence this article via our website: http://example.com"]=> string(0) "" }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Notice: Undefined offset: 11 in /in/8JZnV on line 30 array(6) { [""]=> string(2) "HD" [" Alcoa Earnings Soar; Outlook Stays Upbeat "]=> string(2) "BY" [" By James R. Hagerty and Matthew Day "]=> string(2) "PD" [" 12 July 2011 "]=> string(2) "LP" [" Alcoa Inc.'s profit more than doubled in the second quarter. The giant aluminum producer managed to meet analysts' forecasts. However, profits wereless than expected "]=> string(2) "TD" [" Licence this article via our website: http://example.com"]=> string(0) "" }
Output for 7.3.32 - 7.3.33, 7.4.26
array(6) { [""]=> string(2) "HD" [" Alcoa Earnings Soar; Outlook Stays Upbeat "]=> string(2) "BY" [" By James R. Hagerty and Matthew Day "]=> string(2) "PD" [" 12 July 2011 "]=> string(2) "LP" [" Alcoa Inc.'s profit more than doubled in the second quarter. The giant aluminum producer managed to meet analysts' forecasts. However, profits wereless than expected "]=> string(2) "TD" [" Licence this article via our website: http://example.com"]=> string(0) "" }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Notice: Undefined offset: 11 in /in/8JZnV on line 30 array(6) { [""]=> string(2) "HD" [" Alcoa Earnings Soar; Outlook Stays Upbeat "]=> string(2) "BY" [" By James R. Hagerty and Matthew Day "]=> string(2) "PD" [" 12 July 2011 "]=> string(2) "LP" [" Alcoa Inc.'s profit more than doubled in the second quarter. The giant aluminum producer managed to meet analysts' forecasts. However, profits wereless than expected "]=> string(2) "TD" [" Licence this article via our website: http://example.com"]=> string(0) "" }

preferences:
204.82 ms | 403 KiB | 312 Q