Hello Guys, Will you please help me to figure out how to create a pattern for my preg_match. Here is a example text <td align=center><font size=3>First text to extract</font></td> <td align=center><font size=3>second text to text to extract</font></td> <td align=center><font size=3>second text to text to extract</font></td> What I want to get are those text between <td align=center><font size=3> and </font></td> I'll appreciate the helps... BTW, I tried the following but no success preg_match('/<td align=center><font size=3>(.*?)</font></td>/i', $longtext, $extracted); echo $extracted[0]; Code (markup):
preg_match('{\<td\salign=center\>\<font\ssize=3\>(.*?)\</font\>\</td\>}', $longtext, $extracted); var_dump($extracted); PHP: Note:Metacharacters (must be escaped) http://www.ipaste.org/mg
preg_match() will stop searching after the first match, if you want to search for all matches, you should use preg_match_all: $longtext = '<td align=center><font size=3>First text to extract</font></td> <td align=center><font size=3>second text to text to extract</font></td> <td align=center><font size=3>third text to text to extract</font></td>'; preg_match_all('#<td align=center><font size=3>(.*?)</font></td>#i', $longtext, $matches, PREG_SET_ORDER); /* print_r($matches); should return something like this: Array ( [0] => Array ( [0] => <td align=center><font size=3>First text to extract</font></td> [1] => First text to extract ) [1] => Array ( [0] => <td align=center><font size=3>second text to text to extract</font></td> [1] => second text to text to extract ) [2] => Array ( [0] => <td align=center><font size=3>third text to text to extract</font></td> [1] => third text to text to extract ) ) Where $matches[0][1], $matches[1][1] and $matches[2][1] - text between the tags. */ PHP: