Page 2 of 2

Posted: Sat Sep 01, 2007 11:12 pm
by Z3RO21
And yet another way it can be done:

Code: Select all

$str = 'little';
printf('Mart had a %s lamb.', $str);

Posted: Sun Sep 02, 2007 5:48 am
by volka
and just to put it all together

Code: Select all

// when code execution reaches this statement php concatenates the three strings
$s = 'Mary had a ' . $i . ' lamb.'; 

// when code execution reaches this statement php executes printf
// and printf "replaces" %s with the value of its second parameter
printf('Mart had a %s lamb.', $str);

// when code execution reaches this statement php "replaces" $i
// by the contents of the variable i
$s = "Mary had a $i lamb.";
not too strange, is it?

Posted: Sun Sep 02, 2007 1:39 pm
by asif_phpdn
:D Thanks everybody. I've almost done. Thanks again for replies. But I've another question.

In every example everybody used single quote. But what about double or heredocs (still I'm not clear about this 8O
) ???

Posted: Sun Sep 02, 2007 2:29 pm
by volka
try

Code: Select all

<?php
$i = 1234;
echo <<< dfh
- $i -
dfh;
echo '- $i -';
echo "- $i -";
see also: http://de2.php.net/string

Posted: Sun Sep 02, 2007 8:33 pm
by asif_phpdn
volka wrote:try

Code: Select all

<?php
$i = 1234;
echo <<< dfh
- $i -
dfh;
echo '- $i -';
echo "- $i -";
see also: http://de2.php.net/string
OK. I'll try and tell you immediately.

Posted: Mon Sep 03, 2007 8:48 pm
by asif_phpdn
volka wrote:try

Code: Select all

<?php
$i = 1234;
echo <<< dfh
- $i -
dfh;
echo '- $i -';
echo "- $i -";
see also: http://de2.php.net/string
heredocs and double quote print the value of i.
single quote print what is between the quotes not the value.

Posted: Mon Sep 03, 2007 9:14 pm
by s.dot
Yes.