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 #178007 is a reply to message #178006] Thu, 10 May 2012 13:11 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
M. Strobel wrote:
> Am 10.05.2012 15:05, schrieb Goran:
>> On 10.5.2012 14:44, M. Strobel 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.
>> strtr() ?
>>
>> You could do something like this:
>>
>> $template = 'Your name is %given_name% %family_name%';
>>
>> echo strtr($template, array(
>> '%given_name%' => 'John',
>> '%family_name%' => 'Doe',
>> ));
>
> yeah, create my own variable system. No easier way?
>
> /Str.
>
if you want to program in tcl., i suggest you use tcl.

your example
$t = ' - solved - ';
$msg = 'The problem is $t';

should be
$t = ' - solved - ';
$msg = 'The problem is'.$t;
echo($msg);


--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.
[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: Thu Nov 28 11:37:23 GMT 2024

Total time taken to generate the page: 0.04547 seconds