1

I want to convert css formatted string into array with or without regular expression in PHP. The string is given blow.

$string= "meta[http-equiv=Content-Type]";

OUTPUT Should be like that:-

Array
(
    [0] => Array
        (
            [0] => meta[http-equiv=Content-Type] 
            [1] => meta
            [2] => 
            [3] => 
            [4] => http-equiv
            [5] => =
            [6] => Content-Type
            [7] =>  
        )

)

I am using this pattern but in PHP(7.4) it return empty array.

$pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";

preg_match_all($pattern, trim($string).' ', $matches, PREG_SET_ORDER);
Print_r($matches)

I am unable to find our the result in specified version of PHP. In Other version it is working perfectly.

Gurpal singh
  • 1,511
  • 1
  • 14
  • 27

0 Answers0