<?php
function AttrFromString($string) {
preg_match_all('/(\S+)=["\']?((?:.(?!["\']?\s+(?:\S+)=|[>"\']))+.)["\']?|(\S+)/', $string, $matches);
$items = explode(" ", $string);
$newlist = array();
foreach($items 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'");
preferences:
46.08 ms | 402 KiB | 5 Q