php函数中的单引号和双引号在输出html&;php

php函数中的单引号和双引号在输出html&;php,php,wordpress,function,variables,Php,Wordpress,Function,Variables,我正在尝试使用wordpress主题中的一个钩子,使用一个函数交换网站上的页脚信用 如您所见,“$my_content”变量输出包括php和html 当在这个特定函数之外单独使用时,这个字符串会按预期输出,因此我只能推断问题是由my_content变量为输出结果而添加的单引号引起的 function et_get_footer_credits() { $my_content = '<p id="footer-info">&copy; Copyright <?php

我正在尝试使用wordpress主题中的一个钩子,使用一个函数交换网站上的页脚信用

如您所见,“$my_content”变量输出包括php和html

当在这个特定函数之外单独使用时,这个字符串会按预期输出,因此我只能推断问题是由my_content变量为输出结果而添加的单引号引起的

 function et_get_footer_credits()
{
  $my_content = '<p id="footer-info">&copy; Copyright <?php echo showDateRange('2010'); ?> <a href="<?php echo esc_url( home_url( '/' ) ); ?>">Company name</a>text</p>';
  return $my_content;
}
函数et\u get\u footer\u credits()
{
$my_content='

©;版权文本

; 返回$myu内容; }
不能在字符串中使用php。您应该更改函数,这样html部分将与
$my\u content
变量分离。您可以使用和功能。例如:

function et_get_footer_credits() {
    ob_start();
    ?>

    <p id="footer-info">
        &copy; Copyright <?php echo showDateRange('2010'); ?> 
        <a href="<?php echo esc_url( home_url( '/' ) ); ?>">Company name</a>
        text
    </p>

    <?php
    $my_content = ob_get_clean();

    return $my_content;
}
函数et\u get\u footer\u credits(){
ob_start();
?>

&版权 文本


您不能在字符串中使用php。您应该更改函数,这样html部分将与
$my_content
变量分开。您可以使用and函数。示例:

function et_get_footer_credits() {
    ob_start();
    ?>

    <p id="footer-info">
        &copy; Copyright <?php echo showDateRange('2010'); ?> 
        <a href="<?php echo esc_url( home_url( '/' ) ); ?>">Company name</a>
        text
    </p>

    <?php
    $my_content = ob_get_clean();

    return $my_content;
}
函数et\u get\u footer\u credits(){
ob_start();
?>

&版权 文本


正如RohitS评论所说,您需要关注
$myu内容

$my_content = '<p id="footer-info">&copy; Copyright ' . showDateRange('2010').' <a href="'. esc_url( home_url( '/' ) ) .'">Company name</a>text</p>';

正如RohitS评论所说,您需要关注
$myu内容

$my_content = '<p id="footer-info">&copy; Copyright ' . showDateRange('2010').' <a href="'. esc_url( home_url( '/' ) ) .'">Company name</a>text</p>';

它是什么函数?js还是php?对于php,您需要使用类似$my_content='

©;Copyright.showDateRange('2010')。'text

';它是什么函数?js还是php?对于php,您需要使用类似$my_content='

©;Copyright.showDateRange('2010')的concation.“text

”;哇,谢谢你的回复,第一次奏效…谢谢你的回复,谢谢你的回复,第一次奏效…谢谢你的回复,谢谢你的回复Hanks,这是我最初的解决方案,我无法让它发挥作用,但那也可以,所以谢谢你的帮助谢谢,这是我最初的解决方案,我不能I don’我不能让它工作,但那也可以,所以谢谢你的帮助