gotornot Posted February 16, 2010 Share Posted February 16, 2010 Hi Now i dont know if im asking to much but in a string replace i am looking to change {SHOWOFFERS} with a function is this possible? All i get is just the function output not the function output inserted into the $details template im trying to use. Help please its driving me mad. Example: $from = "{SHOWOFFERS}"; $to = showqblock(); $messagetext = str_replace($from, $to, $details); echo $messagetext; The Function is a form dynamicaaly created to ask for specific questions: Example function showqblock() { global $id; global $affid; global $programid; // check to see if the program is live $selpgq = "SELECT * FROM program WHERE id='$programid'"; $selpgr = mysql_query($selpgq); $selpgrow = mysql_fetch_array($selpgr); echo '<form name="form1" method="post" action="ms_dataprocess.php"><table width="350" border="0" cellspacing="1" cellpadding="1">'; if ($selpgrow["name"]=="1"){echo '<tr><td width="88"><div align="right"><font size="2">Name:</div></td><td width="255"><input type="text" name="name"></td></tr>';} if ($selpgrow["surname"]=="1"){echo '<tr><td width="88"><div align="right"><font size="2">Surname:</div></td><td width="255"><input type="text" name="surname"></td></tr>';} if ($selpgrow["email"]=="1"){echo '<tr><td width="88"><div align="right"><font size="2">Email:</div></td><td width="255"><input type="text" name="email"></td></tr>';} $ipaddy = $_SERVER['REMOTE_ADDR']; if ($selpgrow["ipaddress"]=="1") {echo '<input type="hidden" name= "ip" value="'.$ipaddy.'">';} // now go through and show any extra questions $extq = "SELECT * FROM extraq WHERE programid='$programid'"; $extr = mysql_query($extq); while ($extrow=mysql_fetch_array($extr)) { echo '<tr><td width="88"><div align="right"><font size="2">'.$extrow["name"].':</div></td><td width="255"><input type="text" name="'.$extrow["id"].'"></td></tr>'; } echo'<input name="affiliate" type="hidden" id="affiliate" value="' . $affid . '"> <input name="track" type="hidden" id="track" value="' . $track . '"> <input name="pid" type="hidden" id="pid" value="' . $programid . '"> <tr> <td colspan="2"><div align="center"> <input type="submit" name="Submit" value="Submit"> </div></td> </tr> </table> </form>'; } Quote Link to comment https://forums.phpfreaks.com/topic/192248-str_replace-headache/ Share on other sites More sharing options...
jl5501 Posted February 16, 2010 Share Posted February 16, 2010 I must admint confusion as to what you are trying to achieve here. I cannot think of any circumstances where you would want to replace a string with some php code that you would then want to execute. You can construct your logic so that it executes your function when you need it to. There does not seem to be any need to only create the function at certain times. The bottom line is that str_replace() replaces one string with another, not causes any code in the replacement to execute. Quote Link to comment https://forums.phpfreaks.com/topic/192248-str_replace-headache/#findComment-1013110 Share on other sites More sharing options...
salathe Posted February 16, 2010 Share Posted February 16, 2010 It does not help that your showqblock function is echoing HTML rather than returning it. However, you can grab the echoed text for use in str_replace by changing: $to = showqblock(); To: ob_start(); showqblock(); $to = ob_get_clean(); Quote Link to comment https://forums.phpfreaks.com/topic/192248-str_replace-headache/#findComment-1013122 Share on other sites More sharing options...
gizmola Posted February 16, 2010 Share Posted February 16, 2010 You can use eval() to run php code. It's very dangerous to run code dynamically if you're not 100% sure what you're doing, but if you can't possibly think of a better design, it is possible to take strings of php code and run them dynamically. http://us2.php.net/eval Quote Link to comment https://forums.phpfreaks.com/topic/192248-str_replace-headache/#findComment-1013130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.