【问题标题】:Need Help, put PHP command outside quotations需要帮助,将 PHP 命令放在引号之外
【发布时间】:2017-06-09 17:19:14
【问题描述】:

所以我有这段代码:

<?php  $field['url'] = '<iframe src="http://xxx.xx/= **the_title();**" width="640" height="360" allowscriptaccess="always" allowfullscreen="true" scrolling="no" frameborder="0"></iframe>;'  ?>

我需要将the_title(); 放在引号之外,以便PHP 可以读取它。 甚至可以把它放在两个引号之外吗?

【问题讨论】:

  • 这在一定程度上取决于the_title() 的作用。它是返回还是回显?
  • 如果您注意@ceejayoz 的评论,这两个答案都可以。您的 the_title() 函数必须返回一个字符串。 Utkanos 的答案更简洁一些,因为它不需要使用额外的变量,但是如果你想利用插值并避免连接运算符,你确实可以使用 Mjeebu 的答案。

标签: php iframe


【解决方案1】:

是的。这称为连接,是任何语言中字符串构建的基本部分。在 PHP 中,这是通过 . 连接运算符完成的。

"string etc ".some_func()." continuation of string"

请注意,您可以使用单引号或双引号。

【讨论】:

    【解决方案2】:
    <?php
    $title = the_title();
    $field['url'] = "<iframe src='http://xxx.xx/=$title' width='640' height='360' allowscriptaccess='always' allowfullscreen='true' scrolling='no' frameborder='0'></iframe>;"
    ?>
    

    【讨论】:

      猜你喜欢
      • 2013-06-28
      • 2020-07-19
      • 1970-01-01
      • 2015-04-12
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 2019-05-17
      • 2017-02-07
      相关资源
      最近更新 更多