如何链接标题

时间:2011-07-26 16:03:43

标签: php html5

如何链接此代码中的标题。

 echo "<div id='vblock'>";
      echo "<div style='width:130px;height:95px;float:left'>";
            echo '<a class="bloc_ca" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html"><img src="'.$thumb.'" alt="'.$vtit.'" width="120" height="90"></a></div>';
    echo "<div class='cvtitle'>
        <div><b>".html_entity_decode(substr($video['video_title'],0,100))."..</b></div>
        <div class='cvdisc'><span style='word-break:wrap'>".html_entity_decode(substr($video['video_desc'],0,100))."</span></div>
        <div class='cvviews'> View Count: <b>".$video['views']."</b></div></div></div>";

这是另一个链接的代码。它的工作

echo '<a class="a_bloc" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html">
                <div class="bloc">
                <img src="'.$thumb.'" alt="'.$vtit.'" height="60" width="80">
                <div class="txt">'.$video['video_title'].'</div>
                </div></a>';
    }
    ?>    

提前致谢。

1 个答案:

答案 0 :(得分:0)

echo "<div id='vblock'>";
echo "<div style='width:130px;height:95px;float:left'>";
echo '<a class="bloc_ca" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html"><img src="'.$thumb.'" alt="'.$vtit.'" width="120" height="90"></a></div>';
echo "<div class='cvtitle'><div><a class="bloc_ca" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html"><b>".html_entity_decode(substr($video['video_title'],0,100))."..</b></a></div><div class='cvdisc'><span style='word-break:wrap'>".html_entity_decode(substr($video['video_desc'],0,100))."</span></div><div class='cvviews'> View Count: <b>".$video['views']."</b></div></div></div>";

虽然它很漂亮。你需要做的就是包裹锚:

<a class="bloc_ca" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html">YOUR LINK TEXT</a>

围绕字符串中的标题。因为你正在重用锚点href并且它很长,我倾向于将变量设置为href值,然后使用变量来清晰。