1

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

2 Answers 2

5

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'>";
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.