0

I search a regex, working with PHP, to clean (and minify) my HTML code.

Here's an example of an HTML tag :

<meta name="viewport" content="width=device-width, initial-scale=1" >

And the excepted result :

<meta name=viewport content="width=device-width, initial-scale=1" >

Another example :

<img src="picture.png" alt="Picture" width="800" height="20"/>

And the excepted result :

<img src="picture.png" alt=Picture width=800 height=20/>

I already use this class : https://github.com/mrclay/minify/blob/master/lib/Minify/HTML.php But the feature I want is missing.

Thanks :)

Sébastien
  • 48
  • 4

1 Answers1

1

Use this regex:

"([^"=.]+?)"

And replace by $1.

Regex live here.

Basically, it means:

"                # start quote character
(                # start group
    [^"=.]+?     # if the content between these quotes contains 
                     # equal or dot characters.. then don't match
)                # end group
"                # end quote character