2012-11-15 176 views
0

Previosly我已經在從BBC網站通過捲曲部分頁面內容使用此代碼被拉動,捲曲問題PHP

$c = curl_init('http://news.bbc.co.uk/sport1/hi/football/eng_conf/conference_north_table/default.stm'); 

    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
    $html = curl_exec ($c); 
    if (curl_error($c)) 
     die(curl_error($c)); 

    $startpos = strpos($html, '<table border="1" cellpadding="1" cellspacing="0" class="fulltable">'); 

    $endpos = strpos($html, '<!-- E IINC -->'); 
    $length = $endpos - $startpos; 
    $rest = substr($html, $startpos,$length); 
    $rest = str_replace("border=\"1\" cellpadding=\"1\" cellspacing=\"0\"","border=\"0\" cellpadding=\"0\" cellspacing=\"0\"", $rest); 
    $rest = str_replace('<tr><td colspan="15"><hr/></td></tr>',"", $rest); 

    $rest = str_replace('<tr> 
     <td colspan="15"> 
     <div style="padding: 10px 0 0 0;"><img src=" http://newsimg.bbc.co.uk/sol/shared/img/tbl_spc.gif" height="2px" width="100%"></div> 
     </td> 
    </tr> 
',"", $rest); 

    echo $rest; 
    curl_close($c); 

以前,這一工作正常使用PHP 5.1.3的服務器上,我們已經將網站遷移到運行5.4.8的服務器,但上述代碼不再有效,是否有任何理由?我看不到任何問題。

如果我殺了在$html我得到以下效應初探腳本,

排名表

永久性

移動的文件已移至此處。

但是,如果我瀏覽到通過瀏覽器的網址,我可以查看網頁罰款,因此它顯然沒有任何地方移動(我們遷移服務器之前的捲曲請求工作的事實支持。

+0

任何錯誤信息?你是否插入了調試語句來查看值的外觀? 「不再工作」是什麼意思? –

+0

@OlafDietsche請參閱我的編輯。 – Udders

+0

好習慣**總是**將塊代碼放在括號中。{}}即使是一件襯衫就像你的情況一樣'if(curl_error($ c))....' - 這種習慣可以在較短的時間內節省你的麻煩 –

回答

1

該地址實際上移動更改與第一行:。

$c = curl_init('http://news.bbc.co.uk/sport2/hi/football/eng_conf/conference_north_table/default.stm'); 

現在上面的代碼顯示了我的結果表

1

必須使用

curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); 

遵循重定向。

請參閱PHP: curl_setopt瞭解選項的完整列表。