我觉得问这个很愚蠢,我想粘贴'id',我从数据库检索,这是存储在$link变量到details=...>Read More.
后的<a href>
标签,但我似乎不能让它工作。
<p>
<?php
$longString = $row['name'];
$link = $row['id'];
echo readMoreHelper($longString);
function readMoreHelper($story_desc, $chars = 100) {
$story_desc = substr($story_desc,0,$chars);
$story_desc = substr($story_desc,0,strrpos($story_desc,' '));
$story_desc = $story_desc." <a href='details.php?details=$link>Read More...</a>";
return $story_desc;
}
?>
</p>
需要将$link
作为函数参数传递。
您还遗漏了href
属性末尾的'
。
echo readMoreHelper($longString, $link);
function readMoreHelper($story_desc, $link, $chars = 100) {
$story_desc = substr($story_desc,0,$chars);
$story_desc = substr($story_desc,0,strrpos($story_desc,' '));
$story_desc .= " <a href='details.php?details=$link'>Read More...</a>";
return $story_desc;
}