Chappers Posted November 11, 2006 Share Posted November 11, 2006 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.jpgBut, 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 Quote Link to comment https://forums.phpfreaks.com/topic/26933-help-with-adding-text-after-a-variable-please/ Share on other sites More sharing options...
shocker-z Posted November 11, 2006 Share Posted November 11, 2006 <?php$url = "http://example.com/";echo $url.'images/example.jpg';?>That will do the job using . to seperate the variable and string.RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/26933-help-with-adding-text-after-a-variable-please/#findComment-123161 Share on other sites More sharing options...
Chappers Posted November 11, 2006 Author Share Posted November 11, 2006 Thanks a lot for that quick reply, much appreciated.All the best,James Quote Link to comment https://forums.phpfreaks.com/topic/26933-help-with-adding-text-after-a-variable-please/#findComment-123166 Share on other sites More sharing options...
shocker-z Posted November 11, 2006 Share Posted November 11, 2006 no problem :) im out to get tipsey now ;) Mrs is out working :-D Quote Link to comment https://forums.phpfreaks.com/topic/26933-help-with-adding-text-after-a-variable-please/#findComment-123170 Share on other sites More sharing options...
Chappers Posted November 11, 2006 Author Share Posted November 11, 2006 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"><?phpecho "<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 ;-) Quote Link to comment https://forums.phpfreaks.com/topic/26933-help-with-adding-text-after-a-variable-please/#findComment-123173 Share on other sites More sharing options...
wildteen88 Posted November 11, 2006 Share Posted November 11, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/26933-help-with-adding-text-after-a-variable-please/#findComment-123179 Share on other sites More sharing options...
Chappers Posted November 11, 2006 Author Share Posted November 11, 2006 Both methods work perfectly, many thanks. The space was added to show where I wanted the two elements to join, but to make things clear I had to leave a space otherwise the variable would be read as $urlcss...Best regards,James Quote Link to comment https://forums.phpfreaks.com/topic/26933-help-with-adding-text-after-a-variable-please/#findComment-123183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.