PHP Comparing URL Text

by 8 replies
10
Hi,

Im trying to get a webpage to show an image depending on which keyword the user had used to get to my page. Im doing a PPC click campaign.

For example

When a user clicks my ad they got through the url

http://mysite.co.uk/?keyword={keyword}

Now what I need to do is display an image that is relevent to that keyword on my page.

e.g

http://mysite.co.uk/?keyword=shetland pony

Now I want the code to grab "shetland pony" and display a picture of one that I will have stored in the wordpress library.

But the code needs to be robust enough to understand it needs to look for that word anywhere.

eg

http://mysite.co.uk/?keyword=scottish shetland pony

Should also bring out the pony picture. If none of the keywords match my IF statements it should show nothing at all.

Hope that makes sense
#programming #comparing #php #text #url
  • I haven't tested it but I believe something like this might do the trick...

    <?php

    $keyword = $_GET["keyword"];

    if (stristr($keyword,"pony"))
    {$image = "pony.jpg";}

    elseif (stristr($keyword,"horse"))
    {$image = "horse.jpg";}

    elseif (stristr($keyword,"mule"))
    {$image = "mule.jpg";}

    else {$image = "";}

    ?>

    <!-- HTML below is where image should appear -->

    <img src="<?php echo $image; ?>" />
    • [1] reply
    • Great so I could load that into a php plugin on wordpress and then place short code to where I want the picture to be?

      I will give that a go. Thanks for your help
      • [1] reply
  • Thank you for taking the time to help me out. Much appreciated.
    • [1] reply
    • Hi,

      I have tried your above codes. To be honest Im completely lost. Where is this image folder. Do I need to manually create the folder in the public root of my website domain?

      Im using wordpress as my CMS. And using a plugin to parse the PHP code through a shortcode command.

      I cant for the life of me get an image to display
      • [1] reply

Next Topics on Trending Feed