Karl
Karl

Reputation: 619

Variable in URL in PHP Echo

I need some help..

I have a line of PHP that is echoing a url for me -

<?php foreach($day as $item) : ?>
        <li style="background: url('<?php echo http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=$item['tvdbid']?>')"><?php echo $item['show_name'] ?> </br> <?php echo $item['ep_name'] ?></li>
<?php endforeach ?>

The problem I have is that the URL here -

<li style="background: url('<?php echo http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=$item['tvdbid']?>')">

Appears to kill the code, so I assume my syntax is wrong, if I remove the "background stuff" the code works and the other 2 variables are mapped ok, i'm now wanting to set the backgroud of each li as per the image being returned from the API call, but I can't get it working..i'm sure someone here will sort it really easily for me..

Thanks

Upvotes: 0

Views: 701

Answers (1)

devpro
devpro

Reputation: 16117

Yes you have syntax error in your code:

Modified Example:

<li style='background: url(<?php echo 'http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid='.$item['tvdbid'];?>)'>

Alternate Solution:

<?php
$url = "http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=".$item['tvdbid'];
?>

<li style='background: url(<?php echo $url; ?>)'>

Upvotes: 2

Related Questions