我尝试了很多变化,但我找不到解决方案。以前的输出是这样的:
- 一个字
- b字
- c字等
我已经更改了部分代码,现在输出是:
一个字| 词 b | c字|
如何删除最后一个分隔符?
代码是:
<div id="right">
<div id="synonyms">
<?
$separator = '<span class="pipe">|</span>';
$sql = mysql_query("SELECT DISTINCT word, id_word FROM words WHERE word LIKE '$word' ORDER BY word ASC LIMIT 100");
echo mysql_error();
while ($row=mysql_fetch_row($sql))
{
$word_synonym = $row[0];
$id_word_synonym = $row[1];
$sql2 = mysql_query("SELECT DISTINCT synonym, id_synonym FROM synonyms WHERE id_word = '$id_word_synonym' ORDER BY synonym ASC");
echo mysql_error();
$num_results =mysql_num_rows($sql2);
while ($row=mysql_fetch_row($sql2))
{
$synonym = $row[0];
$id_synonym = $row[1];
$synonym2 = str_replace(" ", "+", $synonym);
echo "".$separator."<a href=".$site_url."/?word=".$synonym2.">".$synonym."</a> ";
}
}
?>
</div>
我尝试添加$separator = substr($separator, -1, 0);
和许多其他建议,但没有结果。