0

以下代码将每个结果生成为文本。我想为每个结果添加一些 html,将其从常规文本更改为 href 标记:

while (!$recordSet->EOF()) {
        if ($pclass_name_list == '') {
            $pclass_name_list .= $recordSet->fields['class_name'];
        } else {
            $pclass_name_list .= ',' . $recordSet->fields['class_name'];
        }
        $recordSet->MoveNext();
    }

以上产生结果 1,结果 2。我想将这些更改为

<a href="">Result 1</a>
<a href="">Result 2</a>

ETC..

4

2 回答 2

0

也许:

if ($pclass_name_list == '') {
        $pclass_name_list .= '<a href="">' . $recordSet->fields['class_name'] . '</a>';
} else {
        $pclass_name_list .= ', <a href="">' . $recordSet->fields['class_name'] . '</a>';
}
于 2012-04-18T15:52:20.257 回答
0

如果您正在将内容简单地添加到字符串中,您可以将变量包装在花括号中并将其包含在带有双引号的字符串中(如下所示),或者您可以使用sprintf函数将内容合并到模板中.

$pclass_name_list = array();
while (!$recordSet->EOF()) {
   $current_class_name = $recordSet->fields['class_name'];
   $pclass_name_list[] = "<a href=\"#\">{$current_class_name}</a>";
   $recordSet->MoveNext();
}
$pclass_name_list = implode(", ", $pclass_name_list);
于 2012-04-18T16:14:14.740 回答