Welcome to WebmasterWorld Guest from 23.20.147.6

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

defining a variable

mixing a variable and a string

     
8:37 pm on May 9, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 6, 2005
posts:41
votes: 0


This is what I need to do:
$filename = '$member' + '.inc';
How do I do this? Thanks
8:52 pm on May 9, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2003
posts:2355
votes: 0


$filename = $member.'.inc';
9:52 pm on May 9, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 30, 2004
posts:95
votes: 0


I just wanted to add that what you are asking about is know as concatenating strings. The above will fix you up just right.
12:51 am on May 10, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 6, 2005
posts:41
votes: 0


thanks :)
3:55 am on June 5, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 6, 2005
posts:41
votes: 0


How do I do this correctly?
echo '$game' + '/' + '$filename';
Thanks
5:03 am on June 5, 2005 (gmt 0)

New User

10+ Year Member

joined:Jan 6, 2005
posts:19
votes: 0


How do I do this correctly?
echo '$game' + '/' + '$filename';
Thanks

<?
echo $game . '/' . $filename;
?>

5:58 pm on June 5, 2005 (gmt 0)

New User

10+ Year Member

joined:June 3, 2005
posts:21
votes: 0


One more way:

echo "$game/$filename";

8:29 pm on June 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


If you echo the variable between ' ' then it is put as string. If you put it between " " then it is parsed as a variable:

<?php
$var = "This is a test";
echo 'This is a variable: $var<br>';
echo "This is what is inside: $var";
?>

Also to ensure that you are doing everything correctly you can put the variable outside of the string:

echo "This is what is inside: ".$var."<br>";

As you see the concatenation in php is a dot (not plus as in javascript).
Best regards
Michal Cibor

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members