$str = "; $a =preg_replace ('/\_data=[\" |\ ') ([a-za-z0-9\_]+) ([\s\] \ ']* '/eis ', "data_array (' \\1 ')", $str);d ie ($a); function Data_array ($key) {$code =add_div ("$key"); return "$code";} function Add_div ($v) { $value = ""; return "$value";}
The results obtained
***********************************************************************************************************
>
>
>
***********************************************************************************************************
The desired result
***********************************************************************************************************
***********************************************************************************************************
***********************************************************************************************************
***********************************************************************************************************
Reply to discussion (solution)
The difference between the two results is not seen!
$a =preg_replace ('/\s+\_data=[\ ' |\ '] ([a-za-z0-9\_]+) ([\s\] \ ']* ' >/eis ', "data_array (' \\1 ')", $str);d ie ($a); function Data_array ($key) { $code =add_div ($key); return $code; } function Add_div ($v) { $value = ">"; return $value; }
$a =preg_replace ('/\s+\_data=[\ ' |\ '] ([a-za-z0-9\_]+) ([\s\] \ ']* ' >/eis ', "data_array (' \\1 ')", $str);d ie ($a); function Data_array ($key) { $code =add_div ($key); return $code; } function Add_div ($v) { $value = ">"; return $value; }
Ask: If my HTML is this form, how should I change the
$str = '
';
The desired result
***********************************************************************************************************
***********************************************************************************************************
$str = ''; $a =preg_replace_callback ('/< (\w+) \s+\_data=[\ "|\"] ([a-za-z0-9\_]+] ([\s\] \ ']*) \s*class= "(. +?)" ><\/\1>/is ', "Data_array", $str);d ie ($a); function Data_array ($key) { $code =add_div ($key [4], $key [2]); return $code; } function Add_div ($class, $id) { $value = ""; return $value; }