Raex Posted August 22, 2014 Share Posted August 22, 2014 (edited) Hi, I need to extract the integers from the source code: <span class=CatLevel1><a onclick="Javascript:ShowMeu('21');">Arts</a> (9768)</span> <span class=CatLevel1><a onclick="Javascript:ShowMeu('271');">Industrial Products</a> (9321)</span> <span class=CatLevel1><a onclick="Javascript:ShowMeu('1273');">Baby</a> (11407)</span> What are the pattern that I can use to retrieve all the integer in the bracket (9768, 9321, 11407)? This is my php code: <!DOCTYPE html> <html> <body> <?php $file_string = file_get_contents('http://www.lelong.com.my/'); preg_match('/<title>(.*)<\/title>/i', $file_string, $title); //pattern $title_out = $title[1]; echo $title_out; ?> </body> </html> Thanks Edited August 22, 2014 by Raex Quote Link to comment https://forums.phpfreaks.com/topic/290586-regex-to-extract-the-integer-from-these-source-code/ Share on other sites More sharing options...
jazzman1 Posted August 22, 2014 Share Posted August 22, 2014 Something like this? <?php $str = <<<EOD <span class=CatLevel1><a onclick="Javascript:ShowMeu('21');">Arts</a> (9768)</span> <span class=CatLevel1><a onclick="Javascript:ShowMeu('271');">Industrial Products</a> (9321)</span> <span class=CatLevel1><a onclick="Javascript:ShowMeu('1273');">Baby</a> (11407)</span> EOD; if (preg_match_all('~\(([\d]+)\)~', $str,$matches)) { echo '<pre>'.print_r($matches[1], true).'</pre>'; } else { echo 'no match'; } Quote Link to comment https://forums.phpfreaks.com/topic/290586-regex-to-extract-the-integer-from-these-source-code/#findComment-1488602 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.