Welcome to WebmasterWorld Guest from 50.19.156.133

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

defining a variable

mixing a variable and a string

     

KrazyKid

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

10+ Year Member



This is what I need to do:
$filename = '$member' + '.inc';
How do I do this? Thanks

bcolflesh

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

WebmasterWorld Senior Member 10+ Year Member



$filename = $member.'.inc';

kazecoder

9:52 pm on May 9, 2005 (gmt 0)

10+ Year Member



I just wanted to add that what you are asking about is know as concatenating strings. The above will fix you up just right.

KrazyKid

12:51 am on May 10, 2005 (gmt 0)

10+ Year Member



thanks :)

KrazyKid

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

10+ Year Member



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

ekram

5:03 am on Jun 5, 2005 (gmt 0)

10+ Year Member



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

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

base64

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

10+ Year Member



One more way:

echo "$game/$filename";

mcibor

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

WebmasterWorld Senior Member 10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month