PHP Help (Off Topic)
by Chris "DiGi" Timberlake · in General Discussion · 03/08/2005 (7:21 pm) · 11 replies
Hello, i'm having a bit of a problem with PHP, i'm trying to echo a php statement inside html, inside a mysql database. So far i haven't been able to figuare out how. Is this possible? If so, how? Please help.
Edit: Yes, i have googled it, if its there, i must've missed it or something.
Edit: Yes, i have googled it, if its there, i must've missed it or something.
About the author
#2
Edit: SP
03/08/2005 (7:27 pm)
No, I mean theres php code inside the html code, inside a mysql database, and I want to echo it, with the php working (of Course).Edit: SP
#3
03/08/2005 (7:28 pm)
Er/...not really understanding...
#4
so it goes like...
?
03/08/2005 (7:29 pm)
Oh wait, so you have a chunk of html inside your db....and that chunk has php code in it...and you want to echo it out?so it goes like...
(database)
(html)
(code)(/code)
(/html)
(/database)?
#5
03/08/2005 (7:33 pm)
Exactly!
#6
in semi-psuedo code it'd prob appear like this:
03/08/2005 (7:40 pm)
Hrm...first I would extract the entire html block from the db...then write a string function to take only the php code (since php code blocks begin with in semi-psuedo code it'd prob appear like this:
Quote:edit: line breaks...wtf?
//first, pull the HTML out of db
$gethtmlsql = "SELECT myhtmlstuff FROM mytable WHERE blah = boo";
$res = mysql_query($gethtmlsql, $conn) or die(mysql_error());
$html = mysql_result($res, 0, "myhtmlstuff");
//now we have all the html code in a variable...extract php code
//NOTE: this part is in pseudo code, since i'm not familar with string functions...
$startindex = find_position_of_text($html, " $endindex = find_position_of_text($html, "?>");
$phpcode = extract_text($html, $startindex, $endindex);
//now, to execute the code, use the eval() function (a REAL function)
eval($phpcode);
?>
hope this helps...
#7
03/08/2005 (7:47 pm)
How would it know where to execute the PHP Codes, if its extracting it from the html?
#8
So then couldn't he just put something like
By the way, what would this be used for, I am pretty sure there may be an easier way to do it, :P.
--Robertp
03/08/2005 (8:01 pm)
EVAL() just executes it as if it were a PHP file correct?So then couldn't he just put something like
<html> <head> <title>I am in a code block, woot!</title> </head> <body> text here <?php //php code here ?> </body> </html>or something to that effect in the database.
By the way, what would this be used for, I am pretty sure there may be an easier way to do it, :P.
--Robertp
#9
Edit: So, its basically echoing a mysql statement (teh html) then echoing a varible inside that html code.
so its like
database
03/08/2005 (8:05 pm)
Echoing varibles, in the html code, in the database. So the possitioning has to be correct.Edit: So, its basically echoing a mysql statement (teh html) then echoing a varible inside that html code.
so its like
<?php echo $mysql_row['content']; ?>
database
<?php $pie = "Pie"; ?> <b> Hi I'm <?php echo $pie; ?> </b>
#10
03/09/2005 (4:31 am)
Oh wait...so you want to echo the VALUE of the variable into a piece of html, and then echoing that into a database?
#11
Proper indentation would probably take a bit of preg_replace() magic.
03/09/2005 (7:17 am)
<?php echo html_entities($StrWithHtmlAndPhpTagsInIt); ?>
Proper indentation would probably take a bit of preg_replace() magic.
Torque Owner Josiah Wang
Erg...then you'd probably put it all in one variable like so...
</?php $htmlstuff = "<html><body>blabhablhablhablhab"; $htmlstuff .= " i love $food</body></html>"; $insertsql = "INSERT into mytable ("text") values ($htmlstuff)"; $res = mysql_query($insertsql, $conn) or die(mysql_error()); ?>(forgive me, i'm a bit rusty >.<)