3v4l.org

run code in 300+ PHP versions simultaneously
<?php function AttrFromString($string) { preg_match_all('/(\S+)=["\']?((?:.(?!["\']?\s+(?:\S+)=|[>"\']))+.)["\']?|(\S+)/', $string, $matches); $newlist = array(); foreach($matches as $yes) { if (strpos($yes, "=")!==false) { $as = explode('=', $yes); } else { $as[0] = $yes; $as[1] = ""; } if (substr($as[1], 0,1) == "'" || substr($as[1], 0,1) == '"') { $as[1] = substr($as[1],1,strlen($as[1])-2); } array_push($newlist, array($as[0]. $as[1])); } var_dump($newlist); } AttrFromString("test=hallo tes2=\"doei\" test3='lol' no-pe ja test='niks'");
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given in /in/SraVK:6 Stack trace: #0 /in/SraVK(6): strpos(Array, '=') #1 /in/SraVK(20): AttrFromString('test=hallo tes2...') #2 {main} thrown in /in/SraVK on line 6
Process exited with code 255.
Output for 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Warning: explode() expects parameter 2 to be string, array given in /in/SraVK on line 7 Notice: Trying to access array offset on value of type null in /in/SraVK on line 13 Notice: Trying to access array offset on value of type null in /in/SraVK on line 13 Notice: Trying to access array offset on value of type null in /in/SraVK on line 16 Notice: Trying to access array offset on value of type null in /in/SraVK on line 16 Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Warning: explode() expects parameter 2 to be string, array given in /in/SraVK on line 7 Notice: Trying to access array offset on value of type null in /in/SraVK on line 13 Notice: Trying to access array offset on value of type null in /in/SraVK on line 13 Notice: Trying to access array offset on value of type null in /in/SraVK on line 16 Notice: Trying to access array offset on value of type null in /in/SraVK on line 16 Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Warning: explode() expects parameter 2 to be string, array given in /in/SraVK on line 7 Notice: Trying to access array offset on value of type null in /in/SraVK on line 13 Notice: Trying to access array offset on value of type null in /in/SraVK on line 13 Notice: Trying to access array offset on value of type null in /in/SraVK on line 16 Notice: Trying to access array offset on value of type null in /in/SraVK on line 16 Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Warning: explode() expects parameter 2 to be string, array given in /in/SraVK on line 7 Notice: Trying to access array offset on value of type null in /in/SraVK on line 13 Notice: Trying to access array offset on value of type null in /in/SraVK on line 13 Notice: Trying to access array offset on value of type null in /in/SraVK on line 16 Notice: Trying to access array offset on value of type null in /in/SraVK on line 16 array(4) { [0]=> array(1) { [0]=> string(0) "" } [1]=> array(1) { [0]=> string(0) "" } [2]=> array(1) { [0]=> string(0) "" } [3]=> array(1) { [0]=> string(0) "" } }
Output for 5.3.1 - 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.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.26
Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Warning: explode() expects parameter 2 to be string, array given in /in/SraVK on line 7 Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Warning: explode() expects parameter 2 to be string, array given in /in/SraVK on line 7 Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Warning: explode() expects parameter 2 to be string, array given in /in/SraVK on line 7 Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Warning: explode() expects parameter 2 to be string, array given in /in/SraVK on line 7 array(4) { [0]=> array(1) { [0]=> string(0) "" } [1]=> array(1) { [0]=> string(0) "" } [2]=> array(1) { [0]=> string(0) "" } [3]=> array(1) { [0]=> string(0) "" } }
Output for 5.3.0
Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Notice: Array to string conversion in /in/SraVK on line 7 Notice: Undefined offset: 1 in /in/SraVK on line 13 Notice: Undefined offset: 1 in /in/SraVK on line 13 Notice: Undefined offset: 1 in /in/SraVK on line 16 Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Notice: Array to string conversion in /in/SraVK on line 7 Notice: Undefined offset: 1 in /in/SraVK on line 13 Notice: Undefined offset: 1 in /in/SraVK on line 13 Notice: Undefined offset: 1 in /in/SraVK on line 16 Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Notice: Array to string conversion in /in/SraVK on line 7 Notice: Undefined offset: 1 in /in/SraVK on line 13 Notice: Undefined offset: 1 in /in/SraVK on line 13 Notice: Undefined offset: 1 in /in/SraVK on line 16 Warning: strpos() expects parameter 1 to be string, array given in /in/SraVK on line 6 Notice: Array to string conversion in /in/SraVK on line 7 Notice: Undefined offset: 1 in /in/SraVK on line 13 Notice: Undefined offset: 1 in /in/SraVK on line 13 Notice: Undefined offset: 1 in /in/SraVK on line 16 array(4) { [0]=> array(1) { [0]=> string(5) "Array" } [1]=> array(1) { [0]=> string(5) "Array" } [2]=> array(1) { [0]=> string(5) "Array" } [3]=> array(1) { [0]=> string(5) "Array" } }
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: Array to string conversion in /in/SraVK on line 6 Notice: Array to string conversion in /in/SraVK on line 6 Notice: Array to string conversion in /in/SraVK on line 6 Notice: Array to string conversion in /in/SraVK on line 6 array(4) { [0]=> array(1) { [0]=> string(5) "Array" } [1]=> array(1) { [0]=> string(5) "Array" } [2]=> array(1) { [0]=> string(5) "Array" } [3]=> array(1) { [0]=> string(5) "Array" } }

preferences:
221.62 ms | 403 KiB | 326 Q