Re: New function request - Variable parsing a string
| From: | Philip Olson | Date: | Wed, 01 Sep 2004 14:41:01 +0000 |
| Subject: | Re: New function request - Variable parsing a string | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-12528@lists.php.net to get a copy of this message | ||
> 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;
>
> }
Just use double quotes, no need for a function:
$string = "* {$abc} * {$klm['klm']} * {$xyz->xyz} *";
echo $string;
Consider rereading that manual page.
Regards,
Philip