I have the following HTML:
<tr valign="top">
<td>Name:</td>
<td>John Doe</td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr valign="top">
<td>Address:</td>
<td>71 view st, Fitchburg, MA 01420</td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr valign="top">
<td>Phone:</td>
<td>978-345-5391</td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr>
<td>Email:</td>
<td>[email protected]</td>
</tr>
I want to capture the values of Name, Phone and Email within the same REGEX pattern, something like:
$pattern = "/Name:<\/td>\s*<td>(.*)<\/td>.*Address:<\/td>\s*<td>(.*)<\/td>.*card ([0-9].*)<\/td>/m";
If I try separately, like:
$pattern = "/Name:<\/td>\s*<td>(.*)<\/td>/m";
$pattern = "/Phone:<\/td>\s*<td>(.*)<\/td>/m";
$pattern = "/Email:<\/td>\s*<td>(.*)<\/td>/m";
is okay. Maybe I don't understand how REGEX works, isn't possible to have more matches in a single pattern?
DOM parserinstead. Those are the right tool for such task.sflag at the end so that it will countnewlinesas white space. 2. Your regex does not match. 3. It is easier to use#instead of/as your regex delimiters since you have/in your haystack.