FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » variable replacement in string
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: variable replacement in string [message #178039 is a reply to message #178038] Fri, 11 May 2012 07:32 Go to previous messageGo to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma:
Senior Member
Am 11.05.2012 04:30, schrieb Jeff North:
> On Thu, 10 May 2012 18:32:58 +0200, in comp.lang.php "M. Strobel"
> <sorry_no_mail_here(at)nowhere(dot)dee>
> <a128trFt9iU1(at)mid(dot)uni-berlin(dot)de> wrote:
>
>> | Am 10.05.2012 16:04, schrieb Jeff North:
>> | > On Thu, 10 May 2012 14:44:08 +0200, in comp.lang.php "M. Strobel"
>> | > <sorry_no_mail_here(at)nowhere(dot)dee>
>> | > <a11rgoFph0U1(at)mid(dot)uni-berlin(dot)de> wrote:
>> | >
>> | >> | Hi,
>> | >> |
>> | >> | I am still searching a function in PHP to execute variable replacement in strings.
>> | >> | Other languages do have this, but for PHP I can only find sprintf() and string replace.
>> | >> |
>> | >> | I have
>> | >> |
>> | >> | $t = ' - solved - ';
>> | >> | $msg = 'The problem is $t';
>> | >> |
>> | >> | I want now:
>> | >> |
>> | >> | echo fxx($msg);
>> | >> |
>> | >> | print out "The problem is - solved - ".
>> | >> |
>> | >> | Please don't tell me about $msg = "The problem is $t"; just think of $msg like a
>> | >> | template read from a file.
>> | >> |
>> | >> | /Str.
>> | >
>> | > How about:
>> | > $msg = 'The problem is {$t}';
>> |
>> | And the next step? How do you print that the problem is solved?
>> |
>> | But maybe you could do a regex replace with this...
>> |
>> | /Str.
>
> echo $msg;

strobel@s114-intel:~> php -a
Interactive shell

php > $t = ' solved!!';
php > $msg = 'The problem is {$t}';
php > echo $msg;
The problem is {$t}
php > $msg = 'The problem is ${t}';
php > echo $msg;
The problem is ${t}
php > $msg = "The problem is ${t}";
php > echo $msg;
The problem is solved!!
php >

You missed something. Only double quotes do it. When you take $msg from a file you
won't be able to do the var replacement.

/Str.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Windows binaries 64bit for PHP
Next Topic: Re: Windows binaries 64bit for PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 05:08:16 GMT 2024

Total time taken to generate the page: 0.03730 seconds