Jump to content

Str_replace Headache


gotornot

Recommended Posts

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>';

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();

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.