preg_match across multiple lines

Here’s how to do php preg_match multi line

Say you have this html:

<select name="foo">
<option value="1">asdfa</option>
<option>asd</option>
</select>

and you want everything between the <select> box, use this php code:

preg_match('/<select name="foo">(.*)</select>/msU',$html,$matches);
print_r($matches);

1 thought on “preg_match across multiple lines

  1. Paul

    This works. But it works only if u use this slash before ” and /
    So here is the corrected version
    preg_match(‘/(.*)/msU’,$html,$matches);
    print_r($matches);

    Reply

Leave a Reply to Paul Cancel reply

Your email address will not be published. Required fields are marked *