• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Parsing a varible into HTML

jetalomar

New Member
hi
I want to parse a php variable into HTML

I know that If i do $var ="something";

i can parse that variable like this

echo "$var";

I want to learn how I can parse the variable in this way. echo "{VAR}";
 
jetalomar said:
I want to learn how I can parse the variable in this way. echo "{VAR}";

it's not a standard way.
so far i know that you have to doubleparse it.
this is an example how you do that.

$toParse = 'echo "{VAR}";';
$toReplace = preg_replace("/\{[a-zA-Z0-9_-]+\}/","\$\\1",$toParse);
eval($toReplace);

the variable $toParse could derive from either external file or strings.
 
I'm trying to use this for a template so I don't have to put in the variable name on the template.
The phpbb board uses this example for their templates.
 
Last edited:
may or may not help you?

PHP:
<?
$string = 'Hello Replace {this} with %That%, are we clear? *no*';
$string = str_replace('{this}','that',$string);
$string = str_replace('%That%','this',$string);
$string = str_replace('no','yes',$string);
echo $string;
?>
 
Back
Top