GarethB Posted May 17, 2011 Share Posted May 17, 2011 Hi Guys and Girls, Long time lurker, first time poster! I am usually able to read through the forums and find and answer without having to start a new thread but I've tried my best to no avail. I am having trouble with the following code: $afname="Gareth"; $alname="B"; $awayoption.="<OPTION VALUE=\"".$afname." \"".$alname."\">".$afname." ".$alname; I would want that to produce the following: <OPTION VALUE=Gareth B">Gareth B The actual result at the moment is: <OPTION VALUE="Gareth "B">Gareth B It has an extra " in the middle. Any ides or help would be great! Cheers Quote Link to comment https://forums.phpfreaks.com/topic/236665-multiple-variables-and-a-space-in-a-string/ Share on other sites More sharing options...
fugix Posted May 17, 2011 Share Posted May 17, 2011 try $awayoption.="<OPTION VALUE=\"{$afname} {$alname}\">".$afname." ".$alname; Quote Link to comment https://forums.phpfreaks.com/topic/236665-multiple-variables-and-a-space-in-a-string/#findComment-1216592 Share on other sites More sharing options...
GarethB Posted May 17, 2011 Author Share Posted May 17, 2011 Wow thank you - worked a treat. I'm still at a very basic level at this point. Is it a case of you can use {} to define variables then where you are using commas within commas, and this will allow a space in the middle? (Oh my I've just confused myself!) Cheers Quote Link to comment https://forums.phpfreaks.com/topic/236665-multiple-variables-and-a-space-in-a-string/#findComment-1216594 Share on other sites More sharing options...
QuickOldCar Posted May 17, 2011 Share Posted May 17, 2011 or even $afname="Gareth"; $alname="B"; $awayoption.="<OPTION VALUE='$afname $alname'>$afname $alname"; can even combine them before like this $afname="Gareth"; $alname="B"; $fullname = "$afname $alname"; $awayoption.="<OPTION VALUE='$fullname'>$fullname"; Quote Link to comment https://forums.phpfreaks.com/topic/236665-multiple-variables-and-a-space-in-a-string/#findComment-1216595 Share on other sites More sharing options...
fugix Posted May 17, 2011 Share Posted May 17, 2011 yeah, as old car points out..basically gareth you were cancatenating your variables incorrectly which lead to you having one too many double quotations...there are several ways to concatenate, really up to personal choice.. Quote Link to comment https://forums.phpfreaks.com/topic/236665-multiple-variables-and-a-space-in-a-string/#findComment-1216599 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.