⊗ppPsRgQP 17 of 84 menu

The Problem of Quotes When Parsing Attributes
Using Regular Expressions in PHP

Attribute quotes can be not only double, but also single:

<img src="1.png"> <img src='2.png'>

Let's account for this in our regular expression:

<?php preg_match_all('#src\s*=\s*(["\'])(.+?)\1#su', $str, $matches, PREG_PATTERN_ORDER); ?>

Let's check that everything works:

<?php var_dump($matches[2]); ?>

Find the contents of all href attributes:

<a href="page1.html">link1</a> <a href='page2.html'>link2</a> <a href = 'page3.html'>link3</a>
itkaidhyhi