# New function request - Variable parsing a string

- Thread: https://externals.io/message/12509
- Original archive: https://news-web.php.net/php.internals/12509
- Started by Herbert Groot Jebbink on 2004-08-31T17:38:13+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #12509 — Herbert Groot Jebbink — 2004-08-31T17:38:13+00:00

URL: https://externals.io/message/12509#12509

Hi,

To speed up a homebuild PHP framework I would like to have a new
function that expands a string with the PHP variables in it, just like
how variable parsing is done for a double-quotes string.

string VariableParsingString ( string string )

Currently I do it with the next eval statement.

eval('$result = "' . str_replace('"', '\\"', $string) . '";');

Greetings, Herbert

---

## #12511 — Rasmus Lerdorf — 2004-08-31T18:00:35+00:00

URL: https://externals.io/message/12509#12511 · In reply to: #12509

http://nl.php.net/parse_str




> Hi,
>
> To speed up a homebuild PHP framework I would like to have a new
> function that expands a string with the PHP variables in it, just like
> how variable parsing is done for a double-quotes string.
>
> string VariableParsingString ( string string )
>
> Currently I do it with the next eval statement.
>
> eval('$result = "' . str_replace('"', '\\"', $string) . '";');
>
> Greetings, Herbert

---

## #12521 — Herbert Groot Jebbink — 2004-09-01T08:14:50+00:00

URL: https://externals.io/message/12509#12521 · In reply to: #12511

Rasmus Lerdorf wrote:

> > […]

> http://nl.php.net/parse_str

I don't want to parse variables FROM a string but I want to parse them
INTO a string as described on the page: 

http://ie.php.net/manual/en/language.types.string.php#language.types.string.parsing

Below a PHP example that shows the function I want.

<?php

  $abc        = '123';
  $klm['klm'] = '456';
  $xyz->xyz   = '789';

  $string = '* {$abc} * {$klm[\'klm\']} * {$xyz->xyz} *';

  $result = parseVarsIntoString ($string);  

  echo $result;
  
  function parseVarsIntoString ($string) {
    
    extract($GLOBALS);

    eval('$result = "' . str_replace('"', '\\"', $string) . '";');

    return $result;

  }

?>

Greetings, Herbert


> 
> 
> 
> 
> > […]
