/    Sign up×
Community /Pin to ProfileBookmark

Stop displaying results – eval()

Hello,
How can I stop this from displaying the results in the browser?

[code]$email_content = eval(“$content”);[/code]

But still have it process $content for submission in an email.

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@zackbloomFeb 17.2007 — [code=php]
ob_start();
eval("$content");
$email_content = ob_get_flush();
[/code]
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 17.2007 — That would probably work normally, however I have a weird situation. So I dont have to type it all out, please take a look at this thread. http://www.phpfreaks.com/forums/index.php/topic,127454

thanks
Copy linkTweet thisAlerts:
@zackbloomFeb 17.2007 — I'm not sure what the problem is. The solution I wrote about is actually what php.net is talking about when it suggests using output control functions.
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 17.2007 — Yeah, but I am trying to execute some php coding in $content
Copy linkTweet thisAlerts:
@zackbloomFeb 17.2007 — Of course you are, thats what eval does. What is the problem, what is not happening correctly?
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 17.2007 — If you read the thread I asked you to it explains quite clearly.
Copy linkTweet thisAlerts:
@zackbloomFeb 17.2007 — I think its fair to ask you to summarize/reiterate your problem if your asking strangers for help.
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 17.2007 — Well I did direct you to the thread to save me doing this. But basically I have a peice of HTML coding in a database. It looks like this at the moment:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Please activate your membership </td>
</tr>
<tr>
<td><a href="http://some.com/activate.php?k=<?php $randomnumber ?>&&u=<?php $username_gen?>">Click on this link to activate your membership </a></td>
</tr>
<tr>
<td>or copy and paste this link to your browser: http://some.com/activate.php?k=<?php $randomnumber ?>&&u=<?php $username_gen ?></td>
</tr>
</table>

I am trying to get it to process the variables in the HTML code/PHP so in my script it will run and send an email out:
$username_gen = base64_encode($username);
$emailselect = mysql_query("select content_content from content where content_name='email_activation_content'");
$emailfrom = mysql_query("select content_content from content where content_name='email_activation_from'");
$emailsubject = mysql_query("select content_content from content where content_name='email_activation_subject'");

<i> </i> list($email_content) = mysql_fetch_array($emailselect);
<i> </i> //eval("$email_content = "{$email_content}";");
<i> </i> $email_content = eval("$email_content = "{$email_content}";");

<i> </i> list($email_from) = mysql_fetch_array($emailfrom);
<i> </i> list($email_subject) = mysql_fetch_array($emailsubject);
<i> </i> $to = $email_address;
<i> </i> $subject = $email_subject;
<i> </i> $message = $email_content;
Copy linkTweet thisAlerts:
@zackbloomFeb 17.2007 — Ahhhhh. eval attempts to evaluate all the text you give it as php code, regardless of the <?php tags. I recommend you use string replacement. You have in your database the following:

[code=html]
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Please activate your membership </td>
</tr>
<tr>
<td><a href="http://some.com/activate.php?k=[{[RANDOM_NUMBER]}]&u=[{[USERNAME]}]">Click on this link to activate your membership </a></td>
</tr>
<tr>
<td>or copy and paste this link to your browser: http://some.com/activate.php?k=[{[RANDOM_NUMBER]}]u=[{[USERNAME]}]</td>
</tr>
</table>
[/code]


Then run the following:

<<<get the text from the database and store it as $file>>>
[code=php]
$file = str_replace(array('[{[RANDOM_NUMBER]}]','[{[USERNAME]}]'),array($randomnumber,$username),$file);
[/code]

If you need it to be more extensible you could use regular expressions to replace the strings with vars.
Copy linkTweet thisAlerts:
@papa_faceauthorFeb 17.2007 — That worked great, thanks a lot ?
Copy linkTweet thisAlerts:
@bokehFeb 17.2007 — Ahhhhh. eval attempts to evaluate all the text you give it as php code[/QUOTE]eval() could be used on that string just to expand the variables.[code=php]<?php

$randomnumber = '12345';
$username_gen = 'bokeh';

$From_DB = '
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Please activate your membership </td>
</tr>
<tr>
<td><a href="http://some.com/activate.php?k={$randomnumber}&u={$username_gen}">Click on this link to activate your membership </a></td>
</tr>
<tr>
<td>or copy and paste this link to your browser: http://some.com/activate.php?k={$randomnumber}&u={$username_gen}</td>
</tr>
</table>
';

eval("$From_DB=<<<ENDn$From_DBnEND;n");

echo $From_DB;

?>[/code]
×

Success!

Help @papa_face spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...