Hey I have this as my preg_match_all line: preg_match_all('<a name="\/(.*)\/s"><\/a><div class="coupon" id="\/(.*)\/s"><table class="details"><tr><th class="code">Code:<\/th><td class="code" id="\/(.*)\/s"><strong>\/(.*)\/s<\/strong> <a class="useButton" href="\/out\/\/(.*)\/s" target="_blank" onclick="javascript:pageTracker._trackPageview(\'\/outgoing\/naff\/\/(.*)\/s\');" rel="nofollow"><span>Use coupon »<\/span><\/a><div class="affTracker"><\/div><\/td><\/tr><tr><th>Discount:<\/th><td class="discount">\/(.*)\/s</td><\/tr><tr><th>Stats:<\/th><td class="stats"><span class="average">\/(.*)\/s</span> <img src="\/(.*)\/s" alt="Coupon voting trend" /><\/td><\/tr><\/table><!-- END: .details -->', $page, $output, PREG_PATTERN_ORDER); PHP: On page I have: <a name="551321"></a><div class="coupon" id="account551321"><table class="details"><tr><th class="code">Code:</th><td class="code" id="code551321"><strong>BIGBRAND</strong> <a class="useButton" href="/out/551321" target="_blank" onclick="javascript:pageTracker._trackPageview('/outgoing/naff/amazon.com');" rel="nofollow"><span>Use coupon »</span></a><div class="affTracker"></div></td></tr><tr><th>Discount:</th><td class="discount">Get $25 off $59 certain food brands at Amazon.com exp 3/31</td></tr><tr><th>Stats:</th><td class="stats"><span class="average">45% success rate</span> <img src="http://assets.retailmenot.com/charts/551/321.png" alt="Coupon voting trend" /></td></tr></table><!-- END: .details --> Code (markup): Repeated several times with different info, I thought the code I had above would work but it's giving me an error.. Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '<' in /home/ryan/public_html/test.php on line 4
The specific error is because of the <img /> tag. you need to change /> to \/>. I also think your \/(.*)\/s should be changed (.*?), for example: <img src="(.*?)" alt="Coupon voting trend" \/> Hope this 2 will do the trick
Still can't get it working ... heres my final code: <?php if(isset($_GET['domain'])) { $page = file_get_contents("http://www.retailmenot.com/view/" . $_GET['domain'] . ""); preg_match_all('<a name="(.*?)"><\/a><div class="coupon" id="(.*?)"><table class="details"><tr><th class="code">Code:<\/th><td class="code" id="(.*?)"><strong>(.*?)<\/strong> <a class="useButton" href="\/out\/(.*?)" target="_blank" onclick="javascript:pageTracker._trackPageview(\'\/outgoing\/naff\/(.*?)\');" rel="nofollow"><span>Use coupon »<\/span><\/a><div class="affTracker"><\/div><\/td><\/tr><tr><th>Discount:<\/th><td class="discount">(.*?)</td><\/tr><tr><th>Stats:<\/th><td class="stats"><span class="average">(.*?)</span> <img src="(.*?)" alt="Coupon voting trend" \/><\/td><\/tr><\/table><!-- END: .details -->#', $page, $output, PREG_PATTERN_ORDER); print_r($output); } else { } ?> PHP:
Perhaps the regex is not correct and need some correcting, you should try shortening it a little and trying adding piece by piece, start with: See if it return results, then add the rest of the regexp, one tag at a time, i'm pretty sure you'll find that you missed something. Thats the "problem" with preg_match, it's all or nothing, no easy way to know whats wrong.
Heh, even that gives the unknown modifer error. EDIT: What exactly does adding # before and after the regex, because that prints an array with values...
Oops Yea, in the help they show a regexp should be surrounded with / (or maybe some use #), from the PHP help: $pattern = '/^def/'; Not sure exactly what is the origin of it and always thought it's not mandatory, but perhaps it is.