Toon Posted December 10, 2008 Share Posted December 10, 2008 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! Thanks a lot, Toon Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/ Share on other sites More sharing options...
flyhoney Posted December 10, 2008 Share Posted December 10, 2008 I would first like to know why you would never need to do this. Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-711945 Share on other sites More sharing options...
redarrow Posted December 10, 2008 Share Posted December 10, 2008 It can be done by php session but what for ...... ???? Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-711947 Share on other sites More sharing options...
dezkit Posted December 10, 2008 Share Posted December 10, 2008 Use preg_replace and RegEx Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-712019 Share on other sites More sharing options...
Toon Posted December 10, 2008 Author Share Posted December 10, 2008 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 https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-712064 Share on other sites More sharing options...
phpSensei Posted December 10, 2008 Share Posted December 10, 2008 lol you can always um use an array or a session or something... but $_POST['field'] << That comes from a FORM, you can't change that unless you change the field name in a form. but....why need this? Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-712067 Share on other sites More sharing options...
corbin Posted December 10, 2008 Share Posted December 10, 2008 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 https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-712086 Share on other sites More sharing options...
DarkWater Posted December 10, 2008 Share Posted December 10, 2008 It can be done by php session but what for ...... ???? What? @thread starter: Why don't you just directly interpolate the variables...? Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-712087 Share on other sites More sharing options...
redarrow Posted December 10, 2008 Share Posted December 10, 2008 user put there name in the dear username field now $name=$username Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-712094 Share on other sites More sharing options...
phpSensei Posted December 11, 2008 Share Posted December 11, 2008 It can be done by php session but what for ...... ???? What? @thread starter: Why don't you just directly interpolate the variables...? Agreed, whats the point of making so complicated lol? Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-712104 Share on other sites More sharing options...
Toon Posted December 11, 2008 Author Share Posted December 11, 2008 Thanks to every one, I made it with Corbin's code! I wish every one a great day from France, Toon Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-712143 Share on other sites More sharing options...
phpSensei Posted December 11, 2008 Share Posted December 11, 2008 Thanks to every one, I made it with Corbin's code! I wish every one a great day from France, Toon Please marked it as solve, i like it when everything is greener around here/ Link to comment https://forums.phpfreaks.com/topic/136423-solved-remplace-name-in-a-text-variable-by-_postname/#findComment-712171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.