<? $i = 0;
foreach( $model->authors as $key => $author){
?>
<?
//if (++$i < count($model->authors)) echo $author->name.';'; else echo $author->name.' ';
if(++$i<count($model->authors))
{
<a href="http://192.168.171.46:9090/search/index?keyword=<? echo $author->name; ?>"><? echo $author->name.';' ?></a>;
}else echo
<a href="http://192.168.171.46:9090/search/index?keyword=<? echo $author->name ?>"><? echo $author->name.' ' ?></a>;
?>
<? }
?>
但它显示此行语法错误未知&lt;在{我无法找到此错误?
之后答案 0 :(得分:1)
假设您正在编写PHP,请执行以下操作:
<?php
$i = 0;
foreach( $model->authors as $key => $author){
if(++$i<count($model->authors)) {
echo "<a href='http://192.168.171.46:9090/search/index?keyword=" . $author->name . "'>" . $author->name . "</a>";
} else {
echo "<a href='http://192.168.171.46:9090/search/index?keyword=" . $author->name . "'>" . $author->name . "</a>";
}
}
?>
答案 1 :(得分:1)
试试这个:
<?php
$i=0;
foreach($model->authors as $key=>$author) {
if(++$i<count($model->authors)) {
echo '<a href="http://192.168.171.46:9090/search/index?keyword='.$author->name.'">'.$author->name.';</a>';
} else {
echo '<a href="http://192.168.171.46:9090/search/index?keyword='.$author->name.'">'.$author->name.' </a>';
}
}
或者,如果你不介意稍微改变,请使用它,因为它更简单:
<?php
$ret='';
foreach($model->authors as $key=>$author)
$ret.=($ret?'; ':'').'<a href="http://192.168.171.46:9090/search/index?keyword='.$author->name.'">'.$author->name.'</a>';
echo $ret;
答案 2 :(得分:0)
<?php
$i = 0;
foreach( $model->authors as $key => $author){
if(++$i<count($model->authors)){
?>
<a href="http://192.168.171.46:9090/search/index?keyword=<?php echo $author->name; ?>"><?php echo $author->name.' '; ?></a>;
<?php
}
else{
?>
<a href="http://192.168.171.46:9090/search/index?keyword=<?php echo $author->name; ?>"><?php echo $author->name.' '; ?></a>
<?php
}
}
?>
我发现你对语法非常困惑 - 也许你应该考虑至少在开始时使用编辑器进行语法检查?
答案 3 :(得分:0)
<?
$i = 0;
foreach ($model->authors as $key => $author):
if (++$i < count($model->authors)): ?>
<a href="http://192.168.171.46:9090/search/index?keyword=<?= $author->name ?>"><?= $author->name ?>;</a>
<? else: ?>
<a href="http://192.168.171.46:9090/search/index?keyword=<?= $author->name ?>"><?= $author->name ?> </a>
<? endif;
endforeach;
?>
或更短的版本。
<?
$i = 0;
foreach ($model->authors as $key => $author): ?>
<a href="http://192.168.171.46:9090/search/index?keyword=<?= $author->name ?>"><?= $author->name,++$i < count($model->authors) ? ';' : ' ' ?></a>
<?
endforeach;
?>