seaten Posted March 2, 2006 Share Posted March 2, 2006 Hi guys,I'm trying to replace a stringA with stringB(this has a variable in it)$theData = ereg_replace('<b>', '<b> $person_name', $theData);echo $theData;The problem is : '<b> $person_name'The value of $person_name is not displayed, so what do I need to add to display the value of the variabe ?Regards and thanks in advance Link to comment https://forums.phpfreaks.com/topic/3927-using-ereg_replacewith-variable-stored-in-string/ Share on other sites More sharing options...
dcro2 Posted March 2, 2006 Share Posted March 2, 2006 Hi there,In order for PHP to parse (add the actual value of the var) you need double quotes around it:$theData = ereg_replace('<b>', "<b> $person_name", $theData);echo $theData;OR:$theData = ereg_replace('<b>', '<b> '.$person_name, $theData);echo $theData; Link to comment https://forums.phpfreaks.com/topic/3927-using-ereg_replacewith-variable-stored-in-string/#findComment-13625 Share on other sites More sharing options...
seaten Posted March 2, 2006 Author Share Posted March 2, 2006 [!--quoteo(post=351046:date=Mar 2 2006, 01:47 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Mar 2 2006, 01:47 PM) [snapback]351046[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi there,In order for PHP to parse (add the actual value of the var) you need double quotes around it:$theData = ereg_replace('<b>', "<b> $person_name", $theData);echo $theData;OR:$theData = ereg_replace('<b>', '<b> '.$person_name, $theData);echo $theData;[/quote]thanks a million Link to comment https://forums.phpfreaks.com/topic/3927-using-ereg_replacewith-variable-stored-in-string/#findComment-13628 Share on other sites More sharing options...
khburres Posted March 2, 2006 Share Posted March 2, 2006 Slight alteration from:$theData = ereg_replace('<b>', '<b> $person_name', $theData);to:$theData = ereg_replace('<b>', '<b> ' . $person_name, $theData);Example:[code]<?php$person_name = "Billy";$theData = "<b> is great";$theData = ereg_replace('<b>', '<b> ' . $person_name, $theData);echo $theData;?>[/code] Link to comment https://forums.phpfreaks.com/topic/3927-using-ereg_replacewith-variable-stored-in-string/#findComment-13632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.