如何用<<
发布于 2024-10-18 12:41:08 字数 1589 浏览 5 评论 0 原文

我想知道如何重写此代码以与 qq 一起使用:

    $containerRight = <<<qq
    <div class="container_right">
        {echoLikeBox()}

        <div class="join_us"><a href="#"><img src="images/join_us.png" width="304" height="44" alt=""></a></div>

        <div class="box2"><a href="#"><img src="images/twitter_big.gif" width="304" height="292" alt=""></a></div>

        <div class="box3"><a href="#"><img src="images/facebook.jpg" width="304" height="257" alt=""></a></div>

        <div class="box4"><a href="#"><img src="images/google_ads.gif" width="304" height="164" alt=""></a></div>
    <!-- container_right end --></div>;
    qq;
    echo $containerRight;  

问题是我不知道如何在 <<< 内 echo 函数。 echoLikBox() 的代码是这样的:

function echoLikeBox()
{
    $likeBox = <<<qq
    <div class="box1">
            <div class="box1_lft"><a href="#"><img src="images/tweet.jpg" width="108" height="20" alt=""></a></div>
            <div class="box1_rht"><a href="#"><img src="images/like.jpg" width="82" height="20" alt=""></a></div>
            <div class="clear"></div>
    </div><!-- box1 end -->
    qq;
    echo $likeBox;
}  

谢谢您的帮助。

编辑:在这里找到解决方案: 在 HEREDOC 字符串中调用 PHP 函数

抱歉,双重发帖。

I am wondering how to rewrite this code to work with qq:

    $containerRight = <<<qq
    <div class="container_right">
        {echoLikeBox()}

        <div class="join_us"><a href="#"><img src="images/join_us.png" width="304" height="44" alt=""></a></div>

        <div class="box2"><a href="#"><img src="images/twitter_big.gif" width="304" height="292" alt=""></a></div>

        <div class="box3"><a href="#"><img src="images/facebook.jpg" width="304" height="257" alt=""></a></div>

        <div class="box4"><a href="#"><img src="images/google_ads.gif" width="304" height="164" alt=""></a></div>
    <!-- container_right end --></div>;
    qq;
    echo $containerRight;  

The problem is that I don't know how to echo function inside the <<<. The code for the echoLikBox() is this:

function echoLikeBox()
{
    $likeBox = <<<qq
    <div class="box1">
            <div class="box1_lft"><a href="#"><img src="images/tweet.jpg" width="108" height="20" alt=""></a></div>
            <div class="box1_rht"><a href="#"><img src="images/like.jpg" width="82" height="20" alt=""></a></div>
            <div class="clear"></div>
    </div><!-- box1 end -->
    qq;
    echo $likeBox;
}  

Thank you for your help.

edit: found the solution here: Calling PHP functions within HEREDOC strings

Sorry for double posting.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟燃烟灭 2024-10-25 12:41:08

您可能想要更改“echoLikeBox()”函数,而不是回显其内容,而是将它们存储为字符串。您无法调用定界符字符串内的函数,但可以输出变量。因此,例如,您可以有:

function echoLikeBox()
{
    $likeBox = <<<qq
    <div class="box1">
            <div class="box1_lft"><a href="#"><img src="images/tweet.jpg" width="108" height="20" alt=""></a></div>
            <div class="box1_rht"><a href="#"><img src="images/like.jpg" width="82" height="20" alt=""></a></div>
            <div class="clear"></div>
    </div><!-- box1 end -->
qq;
    return $likeBox;
}

然后就

$likeBox = echoLikeBox();

$containerRight = <<<qq
    <div class="container_right">
        $likeBox

        ...

在主体内部。

You may want to change the "echoLikeBox()" function to, instead of echoing its contents, store them as a string. You can't make a call to a function inside of heredoc strings, but you can output variables. So, for example, you could have:

function echoLikeBox()
{
    $likeBox = <<<qq
    <div class="box1">
            <div class="box1_lft"><a href="#"><img src="images/tweet.jpg" width="108" height="20" alt=""></a></div>
            <div class="box1_rht"><a href="#"><img src="images/like.jpg" width="82" height="20" alt=""></a></div>
            <div class="clear"></div>
    </div><!-- box1 end -->
qq;
    return $likeBox;
}

and then just

$likeBox = echoLikeBox();

$containerRight = <<<qq
    <div class="container_right">
        $likeBox

        ...

inside of the main body.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文