br3nn4n Posted August 9, 2009 Share Posted August 9, 2009 I have some stuff in a database: <h1>Users</h1> <p> <?php $q = mysql_query("...."); $qa = mysql_fetch_assoc($q); ....more php.... ?> </p> Here's my problem: If I eval() it all, it gives my a parse error about the "<" in the <h1> tag. Makes sense. The fix is to manually echo out any HTML, but that involves having to...yep, manually echo it all. I'm thinking I can have it do the following: 1. Find the HTML portions and stick them in an echo, and addslashes(). 2. Find the stuff inside the <?php and ?> and place it inside an eval(). I'm not sure if I'm just missing something or if there really is no easier way to mix some html and PHP...? Would this be the way you'd do it? If you have any idea I'm more than open to suggestions at this point!! Quote Link to comment https://forums.phpfreaks.com/topic/169445-echo-html-eval-php/ Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 eval('?>' . $string); Quote Link to comment https://forums.phpfreaks.com/topic/169445-echo-html-eval-php/#findComment-893980 Share on other sites More sharing options...
br3nn4n Posted August 9, 2009 Author Share Posted August 9, 2009 eval('?>' . $string); Alright....I apologize but where would I place that / how would I use it? I'll try to see if I can figure it our with my scripts but I'm thinking that you're implying I can leave my database entry as I have it posted above and just use that eval string? Thanks for your quick response!! Quote Link to comment https://forums.phpfreaks.com/topic/169445-echo-html-eval-php/#findComment-894043 Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 Uhm... $string would be a variable containing the code, so in your case, $string would contain: <h1>Users</h1> <p> <?php $q = mysql_query("...."); $qa = mysql_fetch_assoc($q); ....more php.... ?> </p> I.e., the stuff from your database. Quote Link to comment https://forums.phpfreaks.com/topic/169445-echo-html-eval-php/#findComment-894048 Share on other sites More sharing options...
br3nn4n Posted August 9, 2009 Author Share Posted August 9, 2009 Alright, let me run that line you gave me through my code and I'll post back. Quote Link to comment https://forums.phpfreaks.com/topic/169445-echo-html-eval-php/#findComment-894052 Share on other sites More sharing options...
br3nn4n Posted August 9, 2009 Author Share Posted August 9, 2009 You, sir, are a god. I have absolutely no idea why that works (I get that you just start it with a closing tag, but WTH?) but it for some reason seems to I'll let you know if I encounter any problems, thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/169445-echo-html-eval-php/#findComment-894062 Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 eval() evaluates PHP code. It's starting "within" PHP, so to speak. So you just exit PHP by starting with ?>. That's why it works. Quote Link to comment https://forums.phpfreaks.com/topic/169445-echo-html-eval-php/#findComment-894081 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.