3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 5.3.1 - 7.1.0
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 - 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" } }