0

I'm trying to parse the following code:

<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important;">

Essentially what I need is:

Array
(
    [0] => <table
    [1] => border="0"
    [2] => cellpadding="0"
    [3] => cellspacing="0"
    [4] => height="100%"
    [5] => width="100%"
    [6] => id="bodyTable"
    [7] => style="table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important;
)

However when doing this with a simple explode(" ", $str); I'm getting the "style" split up too, is there a simple way to parse this and loop through it?

Saulius Antanavicius
  • 1,371
  • 6
  • 25
  • 55

1 Answers1

0

Try this:

$result = array ();
$str = '<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important;">';
$str_arr = explode (' style', $str);
$result = explode (' ', $str_arr[0]);
array_push($result, 'style'.$str_arr [1]);

echo '<pre>';
print_r($result);
d.coder
  • 1,988
  • 16
  • 23