1

I want to get all Performance ID's from this page .

<?php
$content = file_get_contents("http://www124.popmundo.com/Common/Performances.asp?action=ComingPerformances&ArtistID=1962457");

$regex = "Performances\.asp\?action=Arrangements&amp;PerformanceID=([0-9]+)";
//$regex = "/Performances\.asp\?action=Arrangements&amp;PerformanceID=([0-9]+)/";
//$regex = "/Performances\.asp\?action=Arrangements&amp;PerformanceID=([0-9]+)/s";

//all pattern variations tested, not working

if(preg_match_all($regex, $content, $m))
    print_r($m);
else
    echo "FALSE";

// this is returning FALSE
Eray
  • 7,038
  • 16
  • 70
  • 120
  • You might check out [this][1] question. [1]: http://stackoverflow.com/questions/3627489/php-parse-html-code – Ziggy Aug 19 '11 at 19:30
  • Is there a particular reason you want to use regex? If your code contains large hard to read regexes in string literals it may be more difficult to read and maintain. – Ziggy Aug 19 '11 at 19:38
  • @Ziggy, this is my code : http://pastebin.com/GrBx4CEm – Eray Aug 19 '11 at 19:39

3 Answers3

2

Try this:

 $regex = "/Performances\.asp\?action=Arrangements&amp;PerformanceID=([0-9]+)/";
Jacob Eggers
  • 9,062
  • 2
  • 25
  • 43
  • It still works: http://www.ideone.com/R2nmd. The problem is most likely that `file_get_contents` (can't test it on ideone) doesn't return what you think it does. – dee-see Aug 19 '11 at 19:41
  • Yes, i'm testing on http://www.regexpal.com/ . If i testing on directly `` tags . But if i copy paste all source codes of page, it's not working. – Eray Aug 19 '11 at 19:45
2

Use & instead of &amp; in your regex.

JRL
  • 76,767
  • 18
  • 98
  • 146
  • and here I just built my own and was gonna suggest `"Performances\.asp\?action=Arrangements&PerformanceID=([0-9]{8})"` :p – sg3s Aug 19 '11 at 19:52
0

It looks like an escape problem. Not knowing php, I would guess one of these
might fix it:

$regex = 'Performances\.asp\?action=Arrangements&amp;PerformanceID=([0-9]+)';

or

$regex = "Performances\\.asp\\?action=Arrangements&amp;PerformanceID=([0-9]+)";

or

$regex = '/Performances\.asp\?action=Arrangements&amp;PerformanceID=([0-9]+)/';