2011-08-19 48 views
1

我想從this page獲取所有性能ID。使用REGEX解析數據源

<?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 
+0

您可能會看看[這] [1]個問題。 [1]:http://stackoverflow.com/questions/3627489/php-parse-html-code – Ziggy

+0

@Ziggy,它不使用正則表達式 – Eray

+0

是否有您要使用正則表達式一個特別的原因?如果你的代碼在字符串文字中包含很大的難以閱讀的正則表達式,它可能會更難以閱讀和維護。 – Ziggy

回答

2

使用&而不是&amp;在你的正則表達式。

+0

噢,我的上帝......我們錯過了 – Eray

+0

,在這裏我只是建立了我自己,並建議'「表演\ .asp \?action = Arrangements&PerformanceID =([0-9] {8})」':p – sg3s

2

試試這個:

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

同樣的問題... – Eray

+0

它的作品完美... http://www.ideone.com/R2nmd – Vache

+0

VACH我使用它在這種方式,而不是工作:http://pastebin.com/GrBx4CEm – Eray

0

它看起來像一個逃生問題。不知道PHP的,我猜這些
一個可能解決這個問題:

$正則表達式= 'Performances\.asp\?action=Arrangements&amp;PerformanceID=([0-9]+)';

$正則表達式= "Performances\\.asp\\?action=Arrangements&amp;PerformanceID=([0-9]+)";

$正則表達式= '/Performances\.asp\?action=Arrangements&amp;PerformanceID=([0-9]+)/';

+0

否我們解決問題。這是因爲使用'&'而不是'&'。 – Eray