2013-06-30 23 views
0

我目前正在嘗試獲取OS商務的eBay拍賣模塊,但發現eregi函數已被棄用。我搜索了幾篇文章,但解決方案沒有用。我並不是很瞭解php,但由於任務的性質,我不得不繼續使用它。wamp osCommerce ebay模塊與函數eregi的問題

我顯然遇到的麻煩的代碼是:

 $URL = 'http://cgi6.ebay.com/ws/eBayISAPI.dll?ViewListedItems&userid=' . EBAY_USERID . '&include=0&since=' . AUCTION_ENDED . '&sort=' . AUCTION_SORT . '&rows=0'; 

// Where to Start grabbing and where to End grabbing 
$GrabStart = '<tr bgcolor=\"#ffffff\">'; 
$GrabEnd = 'About eBay'; 

// Open the file 
$file = fopen("$URL", "r"); 

// Read the file 

if (!function_exists('file_get_contents')) { 
    $r = fread($file, 80000); 
} 
else { 
    $r = file_get_contents($URL); 
} 


// Grab just the contents we want 
$stuff = eregi("$GrabStart(.*)$GrabEnd", $r, $content); 

----代碼結束

我有一個類似的問題與分裂,但改變它爆炸與解決現在的問題eregi它不適合preg match,或者我沒有正確地使用它。

感謝您的關注

親切的問候

胡安·費爾南多·貝爾德

回答

0

我不得不承認,我沒有什麼了不起用正則表達式的,所以我嘗試使用PHP 5.2.9測試現有eregi和5.2.6看看它返回了什麼。它總是在$ stuff中返回FALSE,並且$ contents沒有設置爲任何值。所以它只是可能這個代碼從來沒有真正做過什麼!

因此,這是有點危險,因爲我不能確切地知道代碼實際上試圖返回什麼,即它是否希望$ GrabStart和$ GrabEnd出現在結果中。

這可能會完成這項工作。並且可能使用更少的資源,因爲它不需要加載正則表達式引擎進行相當簡單的文本操作。

$r = 'aaa<tr bgcolor=\"#ffffff\">xxxAbout eBaybbb'; 
$conent = ''; 

$GrabStart = '<tr bgcolor=\"#ffffff\">'; 
$GrabEnd = 'About eBay'; 

/* 
* This will return the GrabStart and GrabEnd data in the result 
    p1 3 
    p2 40 
    $content = <tr bgcolor=\"#ffffff\">xxxAbout eBay 
*/ 
$p1 = strpos($r, $GrabStart); 
$p2 = strpos($r, $GrabEnd) + strlen($GrabEnd); 
$content = substr($r, $p1, $p2-$p1); 

echo 'p1 ' . $p1 . PHP_EOL; 
echo 'p2 ' . $p2 . PHP_EOL; 
echo $content . PHP_EOL; 

/* 
* This will just return the data between GrabStart and GrabEnd and not the start and end sentinals 
    p1 27 
    p2 30 
    $content = xxx 
*/ 
$p1 = strpos($r, $GrabStart) + strlen($GrabStart); 
$p2 = strpos($r, $GrabEnd, $p1); 
$content = substr($r, $p1, $p2-$p1); 

echo 'p1 ' . $p1 . PHP_EOL; 
echo 'p2 ' . $p2 . PHP_EOL; 
echo $content . PHP_EOL; 

我希望這有些幫助,儘管它可能會試圖回答很多問題。

+0

嗯嗯嗯我更換jut代碼發佈?或者它需要更多的適應?,因爲我說我不太熟悉PHP所以有點需要知道它是否需要別的東西嘿,抱歉,如果這困擾你,但讓我知道如果我需要適應它,適應什麼,如果不是。很好:D –

+0

剛剛嘗試過,我能想到的更簡單的方式,它沒有工作,我只是煽動了eregi行並粘貼了你的代碼。我知道它可能是愚蠢的,但真的從來沒有用過我的生活中的PHP,所以我有點失去了在這裏 –