示例#1
0
 function stringToArray($string)
 {
     preg_match_all('/
   \\s*(\\w+)              # key                               \\1
   \\s*=\\s*               # =
   (\'|")?               # values may be included in \' or " \\2
   (.*?)                 # value                             \\3
   (?(2) \\2)            # matching \' or " if needed        \\4
   \\s*(?:
     (?=\\w+\\s*=) | \\s*$  # followed by another key= or the end of the string
   )
 /x', $string, $matches, PREG_SET_ORDER);
     $attributes = array();
     foreach ($matches as $val) {
         $attributes[$val[1]] = WPOTools::literalize($val[3]);
     }
     return $attributes;
 }