I have a HTML content like this one
some html text [link id="1"] some html text
some html text [link id="2"] some html text
some html text [link id="3" stat="y"] some html text
some html text [link id="4" stat="y"] some html text
I’m using
var_dump(preg_match_all('/\[link([^\[]+)\]/',$html_tags, $result));
to extract [link] tags from it and it is giving me an array like this
array(2) {
[0]=> array(4) {
[0]=> string(13) "[link id="1"]"
[1]=> string(13) "[link id="2"]"
[2]=> string(21) "[link id="3" stat="y"]"
[3]=> string(21) "[link id="4" stat="y"]"
}
[1]=> array(4) {
[0]=> string(7) " id="1""
[1]=> string(7) " id="2""
[2]=> string(15) " id="3" stat="y""
[3]=> string(15) " id="4" stat="y""
}
}
Can anyone please tell me how I can get the result like this
array (1){
[0]=> array (4) {
[0] => array (2){
[id] => string(1) "1"
[stat] => string(0) ""
}
[1] => array (2){
[id] => string(1) "2"
[stat] => string(0) ""
}
[2] => array (2){
[id] => string(1) "3"
[stat] => string(1) "y"
}
[3] => array (2){
[id] => string(1) "4"
[stat] => string(1) "y"
}
}
}
You can use custom written function and array_map.
http://php.net/manual/en/function.array-map.php
This should work for you.