 <p>You can of course use a regexp, but there are libraries which will do the job quicker and easier. Try using a HTML dom parser, or <a href="http://code.google.com/p/phpquery/" rel="nofollow">phquery</a> which is an implementation of jquery lib in php. It's also <a href="https://packagist.org/packages/electrolinux/phpquery" rel="nofollow">available for Composer</a>. So if you're familiar with jquery syntax, you can find it very neat.</p> <p>Get the html you need using this: $html = pq('.modal.ww')->html();</p>