Re: variable replacement in string



El 10/05/2012 14:44, M. Strobel escribió/wrote:
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.

You haven't really explained why those three methods fail to meet your requirements or how other languages succeed. If we don't know that, any other proposals are likely to be a waste of time.

If you are just looking for some HTML template engine, you have many third-party libraries to choose, from Smarty to Twig.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
.



Relevant Pages

  • Re: variable replacement in string
    ... Other languages do have this, but for PHP I can only find sprintfand string ... echo fxx; ... template read from a file. ...
    (comp.lang.php)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.perl.misc)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.c)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.python)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.lisp)