Jump to content

[SOLVED] remplace [name] in a text variable by $_POST[$name]


Toon

Recommended Posts

Example: Remplace [name] in a text variable by $_POST[$name].

 

So all things between "[]" in this text variable will be remplaced by that PHP post variable of the name between the two "[]".

 

2nd example: So if the variable would contains a [phone_numer] somewhere this will be geplaces in PHP by $_POST[$phone_numer].

 

I hope i have been clear and that you guys can help me!  ;D

Thanks a lot,

Toon

 

Hello,

Thanks for the quick replys!

 

This where i need it for:

I have a form wich will have to be multilanguage and easy to modify for the website owner.

The text like "Dear [name], Thanks for..." will aprear when a visitor has finished filling in the form.

 

I have already tryed with preg_replace but could'nt make it work. I hope someone is into preg_replace around here.

 

Thanks for your help,

Toon

 

Hello,

Thanks for the quick replys!

 

This where i need it for:

I have a form wich will have to be multilanguage and easy to modify for the website owner.

The text like "Dear [name], Thanks for..." will aprear when a visitor has finished filling in the form.

 

I have already tryed with preg_replace but could'nt make it work. I hope someone is into preg_replace around here.

 

Thanks for your help,

Toon

 

 

You could just use str_replace.

 

 

Example:

 

<?php
$some_array = array('name' => 'Corbin', 'foo' => 'bar');

$str = "Hello [name].  Did you know that foo = [foo]?";

$tmp = $str;
foreach($some_array $k => $v) {
    $tmp = str_replace("[{$k}]", $v, $tmp);
}

echo $tmp;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.