2011-02-24 67 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可能是你可以提出的最令人不快的变量名称,如果它实际上是一个字符串。