Re: variable replacement in string



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@xxxxxxxxxxx>
<a11rgoFph0U1@xxxxxxxxxxxxxxxxx> 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.

.



Relevant Pages

  • Re: attempting to return values from array from w/in a function
    ... What I get is an array w/ only the most recent array entry. ... I am new to PHP & do not have formal scripting ... you end up comparing strings, but the test you mean probably is simply: ... case 1: {codeblock} ...
    (comp.lang.php)
  • Re: variable replacement in string
    ... I am still searching a function in PHP to execute variable replacement in strings. ... but for PHP I can only find sprintfand string replace. ... echo strtr($template, array( ...
    (comp.lang.php)
  • Re: Pascal Server Page
    ... this is a Delphi forum, ... assume everybody here prefers Delphi over other languages, ... but PHP is better suited for web ... PHP supports varaiable interpolation in strings which makes ...
    (borland.public.delphi.non-technical)
  • Re: [PHP] pack it in
    ... that's where my brain goes to mush - all strings in php ... in php and such found in these 'binary files' that they need to be ... packallows you to format binary data. ... # Do the conversion the way that the system architecture wants to ...
    (php.general)
  • Re: Storing condition in bitfield?
    ... which I would like to bind form field's validation scheme/condition. ... I believe that in PHP, you can actually store PHP code in strings, and ... opposed to, say, an XML or ASCII representation. ... Putting strings and XML will be of overhead, ...
    (comp.programming)