0

I'm using a piece a code which looks like this (from fpdf to create an array with the html tag attribute as key then the value)

//Extract attributes
$a2=explode(' ',$e);
$tag=strtoupper(array_shift($a2));
$attr=array();
$attrStyle=array();
foreach($a2 as $v)


    if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3))
    $attr[strtoupper($a3[1])]=$a3[2];



    $this->OpenTag($tag,$attr);

It works just fine when $v is something like that.

  • src="images/intro_doc_AA.png"
  • alt="intro"
  • width="388"
  • height="408"

but with HTML5 style format (can't change that) sometimes I have for $v something like that:

  • style="width:
  • 300;
  • height:
  • 485;"

And I'm trying to get something like that so I can use it:

$attrStyle=Array(width->300, height->485) 

Thanks for your time, NG.

NGWarren
  • 1
  • 1

1 Answers1

0
if (preg_match('/([^=]*)=(["\']?)(.*?)\2/s', $v, $a3)) {
    $attr[strtoupper($a3[1])]=$a3[3];
}

But it's obvious: bettter to do not parse HTML by RegExp.

Alex Kapustin
  • 1,869
  • 12
  • 15