2011-02-24 65 views
0

我有一個$object從json對象讀取。我正在使用_filter_url()函數在drupal中將文本顯示爲url。刪除從json輸出分號

每當有超過1個網址時,它會在第1個網址的末尾顯示分號。我如何刪除它?這意味着我需要這些網址以及其下面沒有超鏈接的分號。

function test($object){ 
    echo str_replace('; ','',$object); //this removes the ; but I need the semicolon also to be displayed without any hyperlink below it. 
} 

function test($object) { 
    $x = explode(';',$object); 
    for($i=0;$i<count($x);$i++) { 
     echo _filter_url($x[$i]); //even this removes the semicolon, but i want the semicolon to be displayed at the middle of multiple urls, however the semicolon should not have the hyperlink under 
    } 
} 

thatI得到的輸出是:

URL1 URL2每個URL是在單獨的線

所需的輸出是:

URL1;
URL2

我需要多個網址之間的分號。 但是這個分號不應該是超鏈接的一部分

+0

在您的示例代碼和描述中使用$對象使得這更難理解(因爲它看起來像一個字符串)。你應該向我們展示預期的輸入,錯誤的輸出以及你實際想要的結果。 – mario 2011-02-24 22:28:30

回答

0

試試這個:

trim($object, '; '); 

http://ch2.php.net/trim,這將刪除「」和「;」只從字符串的開頭或結尾開始。

另外請注意,$ bject可能是你可以提出的最令人不快的變量名稱,如果它實際上是一個字符串。