Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5950

Re: variable replacement in string

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!not-for-mail
From "M. Strobel" <sorry_no_mail_here@nowhere.dee>
Newsgroups comp.lang.php
Subject Re: variable replacement in string
Date Fri, 11 May 2012 09:32:54 +0200
Lines 61
Message-ID <a13tl7F15kU1@mid.uni-berlin.de> (permalink)
References <a11rgoFph0U1@mid.uni-berlin.de> <cminq7lal2bu5eefmtef6kor2ko96f2ano@4ax.com> <a128trFt9iU1@mid.uni-berlin.de> <sauoq793q825coiasa8tje12buil6k50td@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de mYcZxcNFbVy0DJ/vej7TGQCRrnjlnlFSX02g58YDV+BeulRC82sdlRuIuIxMoASJ4=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0
In-Reply-To <sauoq793q825coiasa8tje12buil6k50td@4ax.com>
Xref csiph.com comp.lang.php:5950

Show key headers only | View raw


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@nowhere.dee>
> <a128trFt9iU1@mid.uni-berlin.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@nowhere.dee>
>> | > <a11rgoFph0U1@mid.uni-berlin.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.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-10 14:44 +0200
  Re: variable replacement in string The Natural Philosopher <tnp@invalid.invalid> - 2012-05-10 14:00 +0100
    Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-10 15:07 +0200
  Re: variable replacement in string Goran <goran@nospam.com> - 2012-05-10 15:05 +0200
    Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-10 15:08 +0200
      Re: variable replacement in string The Natural Philosopher <tnp@invalid.invalid> - 2012-05-10 14:11 +0100
        Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-10 18:21 +0200
          Re: variable replacement in string The Natural Philosopher <tnp@invalid.invalid> - 2012-05-10 21:50 +0100
            Re: variable replacement in string Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-10 17:06 -0400
              Re: variable replacement in string Scott Johnson <noonehome@chalupasworld.com> - 2012-05-10 15:31 -0700
                Re: variable replacement in string The Natural Philosopher <tnp@invalid.invalid> - 2012-05-11 01:08 +0100
      Re: variable replacement in string Goran <goran@nospam.com> - 2012-05-10 15:13 +0200
        Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-10 18:23 +0200
      Re: variable replacement in string Sandman <mr@sandman.net> - 2012-05-11 16:06 +0200
  Re: variable replacement in string Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-10 09:14 -0400
    Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-10 18:29 +0200
      Re: variable replacement in string Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-10 14:12 -0400
  Re: variable replacement in string Jeff North <jnorthau@yahoo.com.au> - 2012-05-11 00:04 +1000
    Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-10 18:32 +0200
      Re: variable replacement in string Jeff North <jnorthau@yahoo.com.au> - 2012-05-11 12:30 +1000
        Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-11 09:32 +0200
  Re: variable replacement in string Sandman <mr@sandman.net> - 2012-05-10 16:10 +0200
    Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-10 18:37 +0200
      Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-10 18:38 +0200
      Re: variable replacement in string Sandman <mr@sandman.net> - 2012-05-11 15:48 +0200
  Re: variable replacement in string "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2012-05-11 09:58 +0200
    Re: variable replacement in string "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-11 10:31 +0200

csiph-web