PHP内部的HTML不能使PHP功能工作 [英] Can't make PHP function work inside HTML inside PHP

查看:53
本文介绍了PHP内部的HTML不能使PHP功能工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这段代码,它从一个链接中得到一个图像,它根据你的位置而变化:

I wrote this code, it gets an image from a link that varies according to where you are:

<img src='http://chusmix.com/Imagenes/grupos/<?php echo substr(get_search_query(), 1); ?>.jpg'>

如果PHP条件证明是正确的,我想让代码运行,但是我无法让它工作。看来该函数不会返回值,而是会以文本方式进行链接。我的意思是字面上 http://chusmix.com/Imagenes/grupos/ .jpg。但是代码本身是正确的。

I want to make that code run if a PHP condition proves true, but I cannot make it work. It seems that the function doesn't return a value instead it takes the link textually. I mean it goes to http://chusmix.com/Imagenes/grupos/.jpg literally. However the code works correctly by itself.

这是PHP代码:

This is the PHP code:

<?php
    $search=get_search_query();
    $first=$search[0];

    if ($first=="#"){
          echo "<html>";
          echo "<img src='http://chusmix.com/Imagenes/grupos/<?php echo substr(get_search_query(), 1); ?>.jpg'>";
    }
    ?>


推荐答案

您已经在php标签中。因此,不需要<?php ?>

You are already inside the php tag. So there is no need for <?php and ?>.

Try:

Try:

echo "<img src='http://chusmix.com/Imagenes/grupos/".substr($search,1).".jpg'>";

这篇关于PHP内部的HTML不能使PHP功能工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆