开发者

Can't make PHP function work inside HTML inside 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'>

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. Howe开发者_如何学Gover the code works correctly by itself.

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'>";
    }
    ?>


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

Try:

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


Replace line

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

with

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜