Jump to content

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.