【问题标题】:PHP & HTML: How to include .php in concatenated PHP string varPHP & HTML:如何在连接的 PHP 字符串 var 中包含 .php
【发布时间】:2015-03-20 16:31:02
【问题描述】:

我正在尝试做的示例:

<?php
 $html_element = '<form><label>country</label><select>'.include_once("country_list.php").'</select></form>';
?>

我已经尝试了以上和以下:

<?php
 $html_element = '<form><label>country</label><select><?php include_once("country_list.php"); ?></select></form>';
?>

当然,“$html_element”稍后会在某个 div 中回显。那么如何在这个 php 字符串变量中包含“country_list.php”,以便正确拉取?

【问题讨论】:

    标签: php html string variables include


    【解决方案1】:

    如果要包含数据,无论是哪种文件类型,都可以这样做:

    <?php
     $html_element = '<form><label>country</label><select>'.file_get_contents("country_list.php").'</select></form>';
    ?>
    

    【讨论】:

    • 感谢它确实有效,因此在这种情况下 include_once() 函数不正确。
    • country_list.php 中有什么?只是 html 还是有实际的 php 来解析? @sage_x10
    猜你喜欢
    • 1970-01-01
    • 2022-07-19
    • 1970-01-01
    • 1970-01-01
    • 2019-12-29
    • 2017-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多