如何在php中添加html标签

时间:2013-05-14 14:03:37

标签: php html tags

我是php的新手。不知道如何使用表达式。 这是我网站搜索文件中的php代码。 我想添加html,div,li,ul等html标签。我怎么能这样做?

if(mysqli_num_rows($results) >= 1)
{
    $output = "";
    while($row = mysqli_fetch_array($results))
    {
        $output .= "Size: " . $row['fh_Vsize']. "<br />";
        $output .= "Icon: <img src=" . $path .$row['fh_Sicon']. " alt=><br />";
        $output .= "File ID: " . str_replace("_"," ",$row['fh_Sid']) . ""; $nbsp; $nbsp; $output .= "" . $row['fh_Vcaption'] . "<br />";
        $output .= "Description: " . substr(strip_tags($row['fh_Sdescription']),0,150) . "<br />";
        $output .= "Download: <a href=download_" . $row['fh_Sid'] . "/>Download</a><br /><br />";


    }
    echo  $output;
}
else
    echo "There was no matching record for the name " . $searchlink;

像这样的东西。我很抱歉这段代码。我是新来的,将学习基础知识:

<div class="info">
              <h4><a href="'. $path .'download_'. en_string($rec['fh_Sid']) .'/">'.de_string($rec['fh_Sid']) .' ' .$rec['fh_Vcaption'] .' '. $rec['fh_Vextension']. '</a><span class="updated">updated</span></h4>
             <div><img style="float:left;margin-right:5px" src="'. $path . str_replace("t_", "",$rec['fh_Sicon'] ).'"/></div><p>'. substr (strip_tags($rec['fh_Sdescription']),0,170) .' ...</p>
            <ul class="prod-info">
                <li class="none-separator">Last update: <strong>' . strftime("%d %b %Y", $rec['fh_Vdate']) . '</strong></li>
                <li>License: <a href="freeware_pop.html" title="'. $rec['fh_Vlicense'] . '">'. $rec['fh_Vlicense'] . '</a></li>
                <li>Size: <strong>'.$rec['fh_Vsize'].'</strong></li>
                <li>Downloads: <strong>'. $views[$sid] .'</strong></li>
                <li><img src="../../images/dl.png"/>&nbsp;<a href="'.$path.'download_'.$rec['fh_Sid'].'/">Download</a></li>
            </ul>
        </div>

2 个答案:

答案 0 :(得分:0)

对不起,这不是完整的代码 但基本上你可以使用这样的东西

while ($line1 = mysqli_fetch_object($result2)) 
{
$i=0;

$id = $line1->$index; // fetching the whole object id of the SQL table

    foreach ($line1 as $value1) 
    {   
        list($idName,$ext) = explode(".",$value1);
        if ($i==1) // to show only the icon name
        {   
        echo '
        <li id='.$value1.'  name="'.$id.'">
        <form id="addchart'.$idName.'" action="addchart.php" target = "_self" method="post">
        <a id='.$idName.'  onmousedown = "AddorDelete(this.id,this.value)" href = "#" value='.$idName.'>
        <img id="picture" class="icon"  src="images/item/php.png" width="70" style="margin: 0px 0px 0px 0px"/>
        <input type="hidden" name="db" value="'.$db.'" />
        <input type="hidden" name="table" value="'.$table.'" />
        <input type="hidden" name="id" value="'.$id.'" />

你可以echo 'html code and the attribute here' 如果要使用已经预定义的PHP变量分配值,名称或id,请注意语法以指定值,名称或ID。

答案 1 :(得分:0)

我更喜欢这种方式,它会让你拥有自己格式的php和html,并且易于更新:

<?php
if(mysqli_num_rows($results) >= 1)
{
    while($row = mysqli_fetch_array($results))
    {
    ?>
        <div class="info">
              <h4><a href="<?=$path .'download_'. en_string($rec['fh_Sid'])?>/"><?=de_string($rec['fh_Sid']) .' ' .$rec['fh_Vcaption'] .' '. $rec['fh_Vextension']?></a><span class="updated">updated</span></h4>
             <div><img style="float:left;margin-right:5px" src="<?=$path . str_replace("t_", "",$rec['fh_Sicon'] )?>"/></div><p><?=substr (strip_tags($rec['fh_Sdescription']),0,170)?> ...</p>
            <ul class="prod-info">
                <li class="none-separator">Last update: <strong><?=strftime("%d %b %Y", $rec['fh_Vdate'])?></strong></li>
                <li>License: <a href="freeware_pop.html" title="<?=$rec['fh_Vlicense']?>"><?=$rec['fh_Vlicense']?></a></li>
                <li>Size: <strong><?=$rec['fh_Vsize']?></strong></li>
                <li>Downloads: <strong><?=$views[$sid]?></strong></li>
                <li><img src="../../images/dl.png"/>&nbsp;<a href="<?=$path.'download_'.$rec['fh_Sid']?>/">Download</a></li>
            </ul>
        </div>
    <?php
    }
}
else
    echo "There was no matching record for the name " . $searchlink;
?>