dongshadu2546 2017-03-10 23:44
浏览 23
已采纳

重复使用网页中的单词/短语

I use a standard document for all my clients, however want to change their business name and address in several places, so to save time copy and pasting, I want to find a way to reuse words and phrases:

One approach to reusing code that I have found is:

    <html>
<body>

<?php
$color = "red";
$second = "blue";
?>

<p>Roses are <?=$color?></p>
<?=$second?>

<p><b>Note:</b> The shortcut syntax only works with the short_open_tag configuration setting enabled.</p>

</body>
</html>

However, is this best practice? or is there a more standard way to use PHP than this?

The source I got this from said: Shortcut syntax (will only work with the short_open_tag configuration setting enabled)

  • 写回答

3条回答 默认 最新

  • douhuxi4145 2017-03-10 23:53
    关注

    Making repetitive phrases into variables is a good idea. If you are using them across multiple pages you can even abstract them to another file and then include it on each page like this:

    config.php

    <?php
    
    $name    = "Business Name";
    $address = "Address";
    

    index.php

    <?php
    
    include config.php;
    
    ?>
    
    <html>
        <body>
            <p><?php echo $name; ?>
        </body>
    </html>
    

    It's a good idea to use full <?php ?> tags rather than <? ?> as this is the short form and is not always configured to work out of the box on each installation of php!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决