[FX.php List] String Parse still not working
Leo R. Lundgren
leo at finalresort.org
Sun May 18 02:55:07 MDT 2008
18 maj 2008 kl. 05.30 skrev Jonathan Schwartz:
> Hi folks.
>
> This post started as a discussion of my PHPMailer script. I am
> still unsuccessful getting php to parse a string that comes from
> another variable.
>
> In the examples below, only CASE2 works. But I need the string to
> come from another source...$newhtmlstring...not defind within the
> script.
>
>
> CASE1
> echo <<<output
> $newhtmlstring
> output;
> CASE2
> echo <<<EOT
> My name is {$name}.
> EOT;
> CASE3
> echo <<<EOT
> $newhtmlstring
> EOT;
>
> I've been at this off and and on for a week.
>
> Help!
>
> J
>
>
> //CASE1
> $newhtmlstring1 = $findData['recipient_project::mailhtml'][0]; //
> string = My name is {$name}.
> $str1 = <<<EOD
> $newhtmlstring1
> EOD;
> echo $str1;
> //PRODUCES: My name is {$name}.
>
>
> //CASE2
> $newhtmlstring2 = "My name is {$name}.";
> ;
> $str2 = <<<EOD
> $newhtmlstring2
> EOD;
> echo $str2;
> //Produces: My name is Jonathan.
For case1 (in the latter examples, I don't see why you give two sets
of examples): If you indicate that the variable $findData
['recipient_project::mailhtml'][0] contains the string 'My name is
{$name}.', then what it produces seems correct. You assign
(effectively) 'My name is {$name}.' to $newhtmlstring, and then you
assign to $str1 the result of a string with a variable in it, which
is parsed. The result is the contents of the parsed variable, which
is what you had from the beginning, i.e 'My name is {$name}.'.
For case2: Since you say that this case produces "My name is
Jonathan.", it's fair to assume that you have a variable $name set to
'Jonathan' somewhere before the first line of code in case2. What you
assign to $newhtmlstring2 is a string of text containing one
variable, and that variable will be parsed since the string is
delimited by "" ("" parses variables in the string, '' does not). So
the result is the static text plus the contents (if any) of a
variable $name. If $name isn't set before this line of code, or if
it's empty, the result would be "My name is .", but now you
apparently have it set to "Jonathan".
I'm not really sure what the problem is here. I believe you're simply
a bit confused about how the PHP code works and executes :)
-|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20080518/2ace76d0/attachment-0001.html
More information about the FX.php_List
mailing list