English 中文(简体)
php/html php 脚本中的代码 - 如何在 html 中显示 。
原标题:php/html code inside php script - how to display in html
  • 时间:2012-05-28 02:53:34
  •  标签:
  • php
  • html
  • echo

我试图将以下内容放入php区块, 这样我就可以在其它网页上再使用它, 但我得到太多的错误。

谁能告诉我 我怎样才能达到这个目标?

php 文件内的代码块 :

<select name="products">
                        <option value="select">Select</option>
                        <option value="Box" <?php echo @$product_list[ Box ] ?>>Box</option>
                        <option value="TV"  <?php echo @$product_list[ TV ] ?>>TV</option>
                        <option value="Setup"  <?php echo @$product_list[ Setup ] ?>>Setup</option>
                    </select>

我需要在 html 页面里回响的上面的代码。

谢谢!

我刚刚尝试了异语语法,但似乎不起作用,这一定意味着我做错了什么。

编辑:

Any idea why i would get the following error for the code below: syntax error, unexpected T_IF

echo  <select name="products">
                        <option value="select">Select</option>
                        <option value="Box"  . 
                        if (!isset($updatebtn_clicked)){
                            echo @$product_list[ Box ];
                            }elseif (isset($updatebtn_clicked)){
                            echo @$_POST[ Box ];
                        }

                         . > . $product_name[0] . </option>
                                    <option value="select">Select</option>
                        <option value="TV"  . 
                        if (!isset($updatebtn_clicked)){
                            echo @$product_list[ TV ];
                            }elseif (isset($updatebtn_clicked)){
                            echo @$_POST[ TV ];
                        }

                         . > . $product_name[1] . </option>
                         </select>;
最佳回答

使用单引号 :

$select =  <select name="products">
               <option value="select">Select</option>
               <option value="Box"   . $product_list[ Box ] .  >Box</option>
               <option value="TV"    . $product_list[ TV ] .  >TV</option>
               <option value="Setup"   . $product_list[ Setup ] .  >Setup</option>
           </select> ;
echo $select;

关闭并打开 PHP 区块 :

<?php

?>
<select name="products">
    <option value="select">Select</option>
    <option value="Box" <?php echo @$product_list[ Box ] ?>>Box</option>
    <option value="TV"  <?php echo @$product_list[ TV ] ?>>TV</option>
    <option value="Setup"  <?php echo @$product_list[ Setup ] ?>>Setup</option>
</select>
<?php

使用输出缓冲:

<?php
ob_start();
?>
<select name="products">
    <option value="select">Select</option>
    <option value="Box" <?php echo @$product_list[ Box ] ?>>Box</option>
    <option value="TV"  <?php echo @$product_list[ TV ] ?>>TV</option>
    <option value="Setup"  <?php echo @$product_list[ Setup ] ?>>Setup</option>
</select>
<?php
$select = ob_get_clean();
echo $select;
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签