Jump to content

Help with adding text after a variable please


Chappers

Recommended Posts

Hi,

Just a small thing - I've got this code:
[code]<?php
$url = "http://example.com/";
echo "$url images/example.jpg";
?>[/code]
Now that'll echo: http://example.com/ images/example.jpg

But, of course, I don't want a space between the [b]example.com/[/b] and the [b]images/example.jpg[/b]. If I just put the echo as: $urlimages/example.jpg, it doesn't work of course. What's the proper way of doing this?

Many thanks,
James
D'oh! Still can't get it working, because my code is like this:
[code]<?php
$url = "http://example.com/";
?>

<table align="center" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="center">

<?php
echo "<link rel='stylesheet' href='$url css/styles.css' type='text/css'>";
?>[/code]

Where I don't want the current space between [b]$url[/b] and [b]css/styles.css[/b]

Any ideas please?


Enjoy your night out ;-)
You keep putting a space after your variable name in the echo statement. So you are always going to get the space. What you'll want to do is to come out of the echo by adding a double quote before your variable ($url) and then a period (.) now add another period at the end of your variable name and another double quote. So your echo statement should be like this:
[code=php:0]echo "<link rel='stylesheet' href='" . $url . "css/styles.css' type='text/css'>";[/code]


Or you can just ad curly braces around your variable:
[code=php:0]echo "<link rel='stylesheet' href='{$url}css/styles.css' type='text/css'>";[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.