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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.