2015-06-03 55 views
2

這是我的代碼:如何刪除php中的單詞?

<?php 
$url = 'http://www.ebay.de/itm/321773181887'; 
$aufrufe_content = file_get_contents($url); 
$aufrufe1 = explode('<span id="vi-time-wrapperSection">' , $aufrufe_content); 
$aufrufe2 = explode("</span></span>" , $aufrufe1[1]); 
echo $aufrufe2[0]; 
?> 

我怎麼能刪除單詞 「Restzeit:」?

我在其他網站上閱讀我可以用「str_replace」解決我的問題,但我不知道如何在代碼中使用它。

+0

你嘗試並使用它?我的意思是最壞的情況,它會拋出一個錯誤,你必須再次移除它? – Epodax

+2

'str_replace('Restzeit:','',$ string)' –

+0

你可以使用字符串替換,就像第一個參數是你想替換第二個參數是你想替換它的地方,第三個是你想要的變量編輯''''$ newvar = str_replace('Restzeit:','',$ var);''''在這裏閱讀更多內容http://php.net/str_replace – Szenis

回答

0

它是如此簡單:

<?php 
    // ... the first 4 lines 
    $aufrufe2 = explode("</span></span>" , $aufrufe1[1]); 
    $temp = str_replace('Restzeit: ','',$aufrufe2[0]); 
    echo $temp; 
?> 
+0

嘿thx但代碼不工作:c 他們顯示:Restzeit:22Std 18Min 2Sek hmmm; _; –

+0

@MauriceHerbst好吧,它應該現在工作,我刪除了'restzeit'和':' – tektiv

+1

YAY! 現在它工作:)非常感謝你兄弟! –