RE: [PHP] how call a variable in a text

2009-10-22 Thread Samrat Kar
This is always safe to use variables like this...

$text = This is  . $variable;

Or

$text = This is  . $variable[0];

Regards,

Samrat Kar
FRD, BARC

Tel: 022-25597295
Alternate Email: esam...@yahoo.com


-Original Message-
From: Kim Madsen [mailto:php@emax.dk] 
Sent: Thursday, October 22, 2009 2:25 AM
To: a...@ashleysheridan.co.uk
Cc: David Murphy; php-general@lists.php.net
Subject: Re: [PHP] how call a variable in a text

Ashley Sheridan wrote on 2009-10-21 22:43:

 The {} only become really useful when you're trying to reference arrays
 within a string:
 
 $var = array('great', 'boring');
 
 $text = this is {$var[0]}.;
 
 Without the curly braces, PHP wouldn't be able to figure out whether you
 wanted the end string to be 'This is great.' or 'This is [0].' despite
 the variable itself clearly being an array.

Ehh what? This has never been a problem for me:

$text = this is $var[0].;

However this does give an error (or notice, don't recall, haven't seen 
the error in quite a while):

$text = this is $var['0'].;

In that case the solution is the curly brackets:

$text = this is {$var['0']}.;

-- 
Kind regards
Kim Emax - masterminds.dk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.423 / Virus Database: 270.14.25/2450 - Release Date: 10/21/09
16:44:00



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how call a variable in a text

2009-10-22 Thread Thodoris



On Wed, 2009-10-21 at 23:11 +0200, Kim Madsen wrote:

  

Ashley Sheridan wrote on 2009-10-21 22:56:



Try this though:

?php

$var = array(array('great','alright'), 'boring');

print This is $var[0][0].;
  

Print This is different from your previous example :-);

--
Kind regards
Kim Emax - masterminds.dk





Yeah, I just forgot that PHP will correctly work with an array to a
depth of 1 inside of a string. Much like the above advice, I'd taken to
always using {} for arrays inside of strings, although not for strings
inside of strings unless I needed non-white-space text to immediately
follow said string. Would make more sense if I used the braces for
everything, but nobody has ever accused me of making too much sense
before!

Thanks,
Ash
http://www.ashleysheridan.co.uk



  


This will also work (shell like style):

print Test: ${var[0]};

but this won't based on the same principle you mention above:

print Test: ${var[0][0]};

--
Thodoris



Re: [PHP] how call a variable in a text

2009-10-22 Thread Ashley Sheridan
On Thu, 2009-10-22 at 09:53 +0300, Thodoris wrote:

  On Wed, 2009-10-21 at 23:11 +0200, Kim Madsen wrote:
 

  Ashley Sheridan wrote on 2009-10-21 22:56:
 
  
  Try this though:
 
  ?php
 
  $var = array(array('great','alright'), 'boring');
 
  print This is $var[0][0].;

  Print This is different from your previous example :-);
 
  -- 
  Kind regards
  Kim Emax - masterminds.dk
 
  
 
 
  Yeah, I just forgot that PHP will correctly work with an array to a
  depth of 1 inside of a string. Much like the above advice, I'd taken to
  always using {} for arrays inside of strings, although not for strings
  inside of strings unless I needed non-white-space text to immediately
  follow said string. Would make more sense if I used the braces for
  everything, but nobody has ever accused me of making too much sense
  before!
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 
 

 
 This will also work (shell like style):
 
 print Test: ${var[0]};
 
 but this won't based on the same principle you mention above:
 
 print Test: ${var[0][0]};
 

Erm, the braces are meant to go *around* the variable, not around a bit
of it:

print Test: {$var[0][0]};

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] how call a variable in a text

2009-10-22 Thread Andrea Giammarchi

Curly brackets are usually highlighted as well so it is a good practice, 
generally speaking, to use them for double quoted strings and maintainability 
increase automatically.

Regards

 From: esam...@barc.gov.in
 To: php-general@lists.php.net
 Date: Thu, 22 Oct 2009 11:31:53 +0530
 Subject: RE: [PHP] how call a variable in a text
 
 This is always safe to use variables like this...
 
 $text = This is  . $variable;
 
 Or
 
 $text = This is  . $variable[0];
 
 Regards,
 
 Samrat Kar
 FRD, BARC
 
 Tel: 022-25597295
 Alternate Email: esam...@yahoo.com
 
 
 -Original Message-
 From: Kim Madsen [mailto:php@emax.dk] 
 Sent: Thursday, October 22, 2009 2:25 AM
 To: a...@ashleysheridan.co.uk
 Cc: David Murphy; php-general@lists.php.net
 Subject: Re: [PHP] how call a variable in a text
 
 Ashley Sheridan wrote on 2009-10-21 22:43:
 
  The {} only become really useful when you're trying to reference arrays
  within a string:
  
  $var = array('great', 'boring');
  
  $text = this is {$var[0]}.;
  
  Without the curly braces, PHP wouldn't be able to figure out whether you
  wanted the end string to be 'This is great.' or 'This is [0].' despite
  the variable itself clearly being an array.
 
 Ehh what? This has never been a problem for me:
 
 $text = this is $var[0].;
 
 However this does give an error (or notice, don't recall, haven't seen 
 the error in quite a while):
 
 $text = this is $var['0'].;
 
 In that case the solution is the curly brackets:
 
 $text = this is {$var['0']}.;
 
 -- 
 Kind regards
 Kim Emax - masterminds.dk
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 No virus found in this incoming message.
 Checked by AVG - www.avg.com 
 Version: 8.5.423 / Virus Database: 270.14.25/2450 - Release Date: 10/21/09
 16:44:00
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
  
_
Windows Live Hotmail: Your friends can get your Facebook updates, right from 
Hotmail®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009

Re: [PHP] how call a variable in a text

2009-10-22 Thread Thodoris



Erm, the braces are meant to go *around* the variable, not around a 
bit of it:


print Test: {$var[0][0]};

Thanks,
Ash
http://www.ashleysheridan.co.uk




In many cases braces can go around the variable name not the necessarily 
around the whole variable (like the bash scripts). Those are coming from 
the manual:


?php
${date(M)} = Worked;
echo ${date(M)};
?

function test() {
   // NULL -- not what initially expected
   $string = '_POST';
   var_dump(${$string});

   // Works as expected
   var_dump(${'_POST'});

   // Works as expected
   global ${$string};
   var_dump(${$string});

}

So no they are not meant to go around. You can use them this way as well.

--
Thodoris



RE: [PHP] how call a variable in a text

2009-10-22 Thread Andrea Giammarchi


 Erm, the braces are meant to go *around* the variable, not around a bit
 of it:
 
 print Test: {$var[0][0]};

unrelated, just another usage of curly brackets

$_ = 'abc';
$i  = 0;
echo $_{++$i}; // b

Regards
  
_
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail 
you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010

RE: [PHP] how call a variable in a text

2009-10-22 Thread Andrea Giammarchi


 So no they are not meant to go around. You can use them this way as well.

that has almost the same meaning of 

$_ = '_POST';
echo count($$_);

which again, for readability brackets are suggested to improve maintainability

$_ = '_POST';
echo count(${$_});

Regards 
  
_
Windows Live: Make it easier for your friends to see what you’re up to on 
Facebook.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009

Re: [PHP] how call a variable in a text

2009-10-22 Thread Thodoris




 So no they are not meant to go around. You can use them this way as 
well.


that has almost the same meaning of

$_ = '_POST';
echo count($$_);

which again, for readability brackets are suggested to improve 
maintainability


$_ = '_POST';
echo count(${$_});

Regards


http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009


I don't think it is about readability:

$arr[3] = 'test';
$test = 3;

//This prints $test
echo This doesn't work: $$arr[3];

//This prints 3
echo This works: ${$arr[3]};

Using the same type way as before in this thread.

My point is that in the curly braces you protect the way the evaluation 
is going to be made into the string. So you can put them anywhere as 
long as it is meaningful.


See some examples:

http://php.net/manual/en/language.types.string.php

in the complex (curly) syntax section.

--
Thodoris



Re: [PHP] how call a variable in a text

2009-10-22 Thread Thodoris





Using the same type way as before in this thread.




This was supposed to come out as using the same way of thinking.

But the English-Nerdish dictionary came out...

--
Thodoris


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] how call a variable in a text

2009-10-22 Thread Andrea Giammarchi


 I don't think it is about readability:
 
 $arr[3] = 'test';
 $test = 3;
 
 //This prints $test
 echo This doesn't work: $$arr[3];
 
 //This prints 3
 echo This works: ${$arr[3]};
 
 Using the same type way as before in this thread.

Above example is a classic one where readability and maintainability deal well 
together.

First of all everything works as expected but obviously you need to know what 
you need.

It is ambiguous to write $$arr[3] ... what do you expect?

Did you mean the variable derived by $arr[3]?
echo This works: {$$arr[3]};
since curly brackets make the meaning of the expression explicit, it will be 3 
indeed.

What is the less ambiguous, readable, easy to maintain, way to obtain that 
result?

echo This works: {${$arr[3]}};

If our aim is to get the variable with name equal to the value of $arr[3]

Can you see now why I am talking about good practice? Zero ambiguity, and 
that's how I like to code

Regards
  
_
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail 
you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010

Re: [PHP] how call a variable in a text

2009-10-22 Thread Thodoris


  

I don't think it is about readability:

$arr[3] = 'test';
$test = 3;

//This prints $test
echo This doesn't work: $$arr[3];

//This prints 3
echo This works: ${$arr[3]};

Using the same type way as before in this thread.



Above example is a classic one where readability and maintainability deal well 
together.

First of all everything works as expected but obviously you need to know what 
you need.

It is ambiguous to write $$arr[3] ... what do you expect?]
  


No I don't think it is. It produces $test and if this is what you need 
echo it works nice :-) .



Did you mean the variable derived by $arr[3]?
echo This works: {$$arr[3]};
since curly brackets make the meaning of the expression explicit, it will be 3 
indeed.

What is the less ambiguous, readable, easy to maintain, way to obtain that 
result?

echo This works: {${$arr[3]}};

If our aim is to get the variable with name equal to the value of $arr[3]

Can you see now why I am talking about good practice? Zero ambiguity, and 
that's how I like to code

Regards

  


Although I totally  agree with the way of thinking and it is my style as 
well.


But I though that the point of the thread was to present ways of putting 
vars inside strings...


--
Thodoris



Re: [PHP] how call a variable in a text

2009-10-22 Thread Martin Scotta
On Thu, Oct 22, 2009 at 8:40 AM, Thodoris t...@kinetix.gr wrote:




 I don't think it is about readability:

 $arr[3] = 'test';
 $test = 3;

 //This prints $test
 echo This doesn't work: $$arr[3];

 //This prints 3
 echo This works: ${$arr[3]};

 Using the same type way as before in this thread.



 Above example is a classic one where readability and maintainability deal
 well together.

 First of all everything works as expected but obviously you need to know
 what you need.

 It is ambiguous to write $$arr[3] ... what do you expect?]



 No I don't think it is. It produces $test and if this is what you need
 echo it works nice :-) .

  Did you mean the variable derived by $arr[3]?
 echo This works: {$$arr[3]};
 since curly brackets make the meaning of the expression explicit, it will
 be 3 indeed.

 What is the less ambiguous, readable, easy to maintain, way to obtain that
 result?

 echo This works: {${$arr[3]}};

 If our aim is to get the variable with name equal to the value of $arr[3]

 Can you see now why I am talking about good practice? Zero ambiguity, and
 that's how I like to code

 Regards




 Although I totally  agree with the way of thinking and it is my style as
 well.

 But I though that the point of the thread was to present ways of putting
 vars inside strings...

 --
 Thodoris


PHP knows that before $ and {} there is a variable name so, this is
completely correct for PHP

?php // tested on PHP 5.2.6, is this correct on PHP = 5 ?

$name = 'Martin';
$var = 'name';

echo $name {$name} ${name} ${ 'name' } ${$var} {$$var} ${${ 'var' }}
,PHP_EOL;
// am I missing any other way here?

// this is non-sense, but funny :)
$a = 'b';
$b = 'c';
$c = 'd';
$d = 'e';
$e = 'a';

$swap = 'a';

for($i=0,$e=rand(1, 100); $i$e; ++$i)
$swap = ${ $swap };

echo $swap, PHP_EOL;

I feel ${ $var } safer for developers than $$var because I feel it more
readable.
$$var can be interpreted by a typo for somebody, while with ${ $var } there
is no doubt what was the coder intent.


-- 
Martin Scotta


Re: [PHP] how call a variable in a text

2009-10-21 Thread Andrew Ballard
2009/10/21 Bulend Kolay bma...@ihlas.net.tr:
 I 'll send a mail in html form using php5.

 cat send.php
 ?php
 $variable=date1 ;
 ..
 ..
 $message='

 b There is a text $variable  trial. /b
 ';

 mail($to, $subject, $message, $headers) ;
 ?

 when I run send.php, I get the mail. But I can't call variable called
 variable. it comes as string.
 How can I correct this?


You need to use double quotes (or HEREDOC) if you want PHP to replace
$variable with its value in the string:

$message=

b There is a text $variable  trial. /b
;

or

$message = MESSAGE

b There is a text $variable  trial. /b
MESSAGE;



Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] how call a variable in a text

2009-10-21 Thread David Murphy
This is actually much better  the {  and } make it very obvious where the  
variable is and also it can keep odd issues from occurring sometimes.

$message=b There is a text {$variable}  trial. /b ;

There is always sprint type functions also.


David

-Original Message-
From: Andrew Ballard [mailto:aball...@gmail.com] 
Sent: Wednesday, October 21, 2009 3:23 PM
To: Bulend Kolay
Cc: php-general@lists.php.net
Subject: Re: [PHP] how call a variable in a text

2009/10/21 Bulend Kolay bma...@ihlas.net.tr:
 I 'll send a mail in html form using php5.

 cat send.php
 ?php
 $variable=date1 ;
 ..
 ..
 $message='

 b There is a text $variable  trial. /b ';

 mail($to, $subject, $message, $headers) ; ?

 when I run send.php, I get the mail. But I can't call variable called 
 variable. it comes as string.
 How can I correct this?


You need to use double quotes (or HEREDOC) if you want PHP to replace $variable 
with its value in the string:

$message=

b There is a text $variable  trial. /b ;

or

$message = MESSAGE

b There is a text $variable  trial. /b MESSAGE;



Andrew

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php

No virus found in this outgoing message.
Checked by AVG - www.avg.com
Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date: 10/20/09 
18:42:00
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: [PHP] how call a variable in a text

2009-10-21 Thread Ashley Sheridan
On Wed, 2009-10-21 at 15:40 -0500, David Murphy wrote:

 This is actually much better  the {  and } make it very obvious where the  
 variable is and also it can keep odd issues from occurring sometimes.
   
   $message=b There is a text {$variable}  trial. /b ;
 
 There is always sprint type functions also.
 
 
 David
 
 -Original Message-
 From: Andrew Ballard [mailto:aball...@gmail.com] 
 Sent: Wednesday, October 21, 2009 3:23 PM
 To: Bulend Kolay
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] how call a variable in a text
 
 2009/10/21 Bulend Kolay bma...@ihlas.net.tr:
  I 'll send a mail in html form using php5.
 
  cat send.php
  ?php
  $variable=date1 ;
  ..
  ..
  $message='
 
  b There is a text $variable  trial. /b ';
 
  mail($to, $subject, $message, $headers) ; ?
 
  when I run send.php, I get the mail. But I can't call variable called 
  variable. it comes as string.
  How can I correct this?
 
 
 You need to use double quotes (or HEREDOC) if you want PHP to replace 
 $variable with its value in the string:
 
 $message=
 
 b There is a text $variable  trial. /b ;
 
 or
 
 $message = MESSAGE
 
 b There is a text $variable  trial. /b MESSAGE;
 
 
 
 Andrew
 
 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
 http://www.php.net/unsub.php
 No virus found in this outgoing message.
 Checked by AVG - www.avg.com 
 Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date: 10/20/09 
 18:42:00
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


The {} only become really useful when you're trying to reference arrays
within a string:

$var = array('great', 'boring');

$text = this is {$var[0]}.;

Without the curly braces, PHP wouldn't be able to figure out whether you
wanted the end string to be 'This is great.' or 'This is [0].' despite
the variable itself clearly being an array.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] how call a variable in a text

2009-10-21 Thread David Murphy
True however   K.I.S.S  would say , if  you can use it  like

 

 

echo “This is a statement {$Blah}.”;

echo “This is also a statement {$objBlah-BlahString}.”;

echo “This is also a statement {$tBlah[‘BlahKey’]}.”;

 

 

You should do it so you are always using the same expected format, cleaner for 
readability and training other people to understand how you code.

 

 

This is my personal thoughts on it, everyone has their own prefs.

 

David

 

From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Wednesday, October 21, 2009 3:43 PM
To: David Murphy
Cc: php-general@lists.php.net
Subject: RE: [PHP] how call a variable in a text

 

On Wed, 2009-10-21 at 15:40 -0500, David Murphy wrote: 

 
This is actually much better  the {  and } make it very obvious where the  
variable is and also it can keep odd issues from occurring sometimes.

$message=b There is a text {$variable}  trial. /b ;
 
There is always sprint type functions also.
 
 
David
 
-Original Message-
From: Andrew Ballard [mailto:aball...@gmail.com] 
Sent: Wednesday, October 21, 2009 3:23 PM
To: Bulend Kolay
Cc: php-general@lists.php.net
Subject: Re: [PHP] how call a variable in a text
 
2009/10/21 Bulend Kolay bma...@ihlas.net.tr:
 I 'll send a mail in html form using php5.
 
 cat send.php
 ?php
 $variable=date1 ;
 ..
 ..
 $message='
 
 b There is a text $variable  trial. /b ';
 
 mail($to, $subject, $message, $headers) ; ?
 
 when I run send.php, I get the mail. But I can't call variable called 
 variable. it comes as string.
 How can I correct this?
 
 
You need to use double quotes (or HEREDOC) if you want PHP to replace $variable 
with its value in the string:
 
$message=
 
b There is a text $variable  trial. /b ;
 
or
 
$message = MESSAGE
 
b There is a text $variable  trial. /b MESSAGE;
 
 
 
Andrew
 
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php
No virus found in this outgoing message.
Checked by AVG - www.avg.com 
Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date: 10/20/09 
18:42:00
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


The {} only become really useful when you're trying to reference arrays within 
a string:

$var = array('great', 'boring');

$text = this is {$var[0]}.;

Without the curly braces, PHP wouldn't be able to figure out whether you wanted 
the end string to be 'This is great.' or 'This is [0].' despite the variable 
itself clearly being an array.


Thanks,
Ash
http://www.ashleysheridan.co.uk



 


No virus found in this outgoing message.
Checked by AVG - www.avg.com
Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date: 10/20/09 
18:42:00
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] how call a variable in a text

2009-10-21 Thread Kim Madsen

Ashley Sheridan wrote on 2009-10-21 22:43:


The {} only become really useful when you're trying to reference arrays
within a string:

$var = array('great', 'boring');

$text = this is {$var[0]}.;

Without the curly braces, PHP wouldn't be able to figure out whether you
wanted the end string to be 'This is great.' or 'This is [0].' despite
the variable itself clearly being an array.


Ehh what? This has never been a problem for me:

$text = this is $var[0].;

However this does give an error (or notice, don't recall, haven't seen 
the error in quite a while):


$text = this is $var['0'].;

In that case the solution is the curly brackets:

$text = this is {$var['0']}.;

--
Kind regards
Kim Emax - masterminds.dk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] how call a variable in a text

2009-10-21 Thread Ashley Sheridan
On Wed, 2009-10-21 at 15:51 -0500, David Murphy wrote:
 True however   K.I.S.S  would say , if  you can use it  like
 
  
 
  
 
 echo “This is a statement {$Blah}.”;
 
 echo “This is also a statement {$objBlah-BlahString}.”;
 
 echo “This is also a statement {$tBlah[‘BlahKey’]}.”;
 
  
 
  
 
 You should do it so you are always using the same expected format,
 cleaner for readability and training other people to understand how
 you code.
 
  
 
  
 
 This is my personal thoughts on it, everyone has their own prefs.
 
  
 
 David
 
  
 
 
 From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
 Sent: Wednesday, October 21, 2009 3:43 PM
 To: David Murphy
 Cc: php-general@lists.php.net
 Subject: RE: [PHP] how call a variable in a text
 
 
 
  
 
 On Wed, 2009-10-21 at 15:40 -0500, David Murphy wrote: 
 
 
  
 This is actually much better  the {  and } make it very obvious where the  
 variable is and also it can keep odd issues from occurring sometimes.
 
 $message=b There is a text {$variable}  trial. /b ;
  
 There is always sprint type functions also.
  
  
 David
  
 -Original Message-
 From: Andrew Ballard [mailto:aball...@gmail.com] 
 Sent: Wednesday, October 21, 2009 3:23 PM
 To: Bulend Kolay
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] how call a variable in a text
  
 2009/10/21 Bulend Kolay bma...@ihlas.net.tr:
  I 'll send a mail in html form using php5.
  
  cat send.php
  ?php
  $variable=date1 ;
  ..
  ..
  $message='
  
  b There is a text $variable  trial. /b ';
  
  mail($to, $subject, $message, $headers) ; ?
  
  when I run send.php, I get the mail. But I can't call variable called 
  variable. it comes as string.
  How can I correct this?
  
  
 You need to use double quotes (or HEREDOC) if you want PHP to replace 
 $variable with its value in the string:
  
 $message=
  
 b There is a text $variable  trial. /b ;
  
 or
  
 $message = MESSAGE
  
 b There is a text $variable  trial. /b MESSAGE;
  
  
  
 Andrew
  
 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
 http://www.php.net/unsub.php
 No virus found in this outgoing message.
 Checked by AVG - www.avg.com 
 Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date: 10/20/09 
 18:42:00
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 The {} only become really useful when you're trying to reference
 arrays within a string:
 
 $var = array('great', 'boring');
 
 $text = this is {$var[0]}.;
 
 Without the curly braces, PHP wouldn't be able to figure out whether
 you wanted the end string to be 'This is great.' or 'This is [0].'
 despite the variable itself clearly being an array.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 
 
 
  
 
 
 
 No virus found in this outgoing message.
 Checked by AVG - www.avg.com 
 Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date: 10/20/09 
 18:42:00
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


I reckon that part is all down to personal preference. Interesting to
see it works on objects too though. I've not seen that before, I was
always breaking outside of the strings for that type of thing.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] how call a variable in a text

2009-10-21 Thread Ashley Sheridan
On Wed, 2009-10-21 at 22:54 +0200, Kim Madsen wrote:

 Ashley Sheridan wrote on 2009-10-21 22:43:
 
  The {} only become really useful when you're trying to reference arrays
  within a string:
  
  $var = array('great', 'boring');
  
  $text = this is {$var[0]}.;
  
  Without the curly braces, PHP wouldn't be able to figure out whether you
  wanted the end string to be 'This is great.' or 'This is [0].' despite
  the variable itself clearly being an array.
 
 Ehh what? This has never been a problem for me:
 
 $text = this is $var[0].;
 
 However this does give an error (or notice, don't recall, haven't seen 
 the error in quite a while):
 
 $text = this is $var['0'].;
 
 In that case the solution is the curly brackets:
 
 $text = this is {$var['0']}.;
 
 -- 
 Kind regards
 Kim Emax - masterminds.dk
 

Try this though:

?php

$var = array(array('great','alright'), 'boring');

print This is $var[0][0].;

?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] how call a variable in a text

2009-10-21 Thread Kim Madsen

Ashley Sheridan wrote on 2009-10-21 22:56:


Try this though:

?php

$var = array(array('great','alright'), 'boring');

print This is $var[0][0].;


Print This is different from your previous example :-);

--
Kind regards
Kim Emax - masterminds.dk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how call a variable in a text

2009-10-21 Thread Ashley Sheridan
On Wed, 2009-10-21 at 23:11 +0200, Kim Madsen wrote:

 Ashley Sheridan wrote on 2009-10-21 22:56:
 
  Try this though:
  
  ?php
  
  $var = array(array('great','alright'), 'boring');
  
  print This is $var[0][0].;
 
 Print This is different from your previous example :-);
 
 -- 
 Kind regards
 Kim Emax - masterminds.dk
 


Yeah, I just forgot that PHP will correctly work with an array to a
depth of 1 inside of a string. Much like the above advice, I'd taken to
always using {} for arrays inside of strings, although not for strings
inside of strings unless I needed non-white-space text to immediately
follow said string. Would make more sense if I used the braces for
everything, but nobody has ever accused me of making too much sense
before!

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] how call a variable in a text

2009-10-21 Thread Shawn McKenzie
Ashley Sheridan wrote:
 On Wed, 2009-10-21 at 22:54 +0200, Kim Madsen wrote:
 
 Ashley Sheridan wrote on 2009-10-21 22:43:

 The {} only become really useful when you're trying to reference arrays
 within a string:

 $var = array('great', 'boring');

 $text = this is {$var[0]}.;

 Without the curly braces, PHP wouldn't be able to figure out whether you
 wanted the end string to be 'This is great.' or 'This is [0].' despite
 the variable itself clearly being an array.
 Ehh what? This has never been a problem for me:

 $text = this is $var[0].;

 However this does give an error (or notice, don't recall, haven't seen 
 the error in quite a while):

 $text = this is $var['0'].;

 In that case the solution is the curly brackets:

 $text = this is {$var['0']}.;

 -- 
 Kind regards
 Kim Emax - masterminds.dk

 
 Try this though:
 
 ?php
 
 $var = array(array('great','alright'), 'boring');
 
 print This is $var[0][0].;
 
 ?
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 

And since we are trying to cover all possible ways (works with double
quotes also):

$message = 'b There is a text ' . $variable . ' trial. /b';

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php