Novice@PHP Posted June 8, 2010 Share Posted June 8, 2010 I'm trying to output php with PHP. Example. <?php if ( is_user_logged_in() ) { echo '[b]<?php if(function_exists('twit_connect')){twit_connect();} ?>[/b]'; } else { echo 'Welcome, visitor!'; }; ?> I know I'm way off in what I'm trying to do. What do I need to do? Thanks On a side note Google is fruitless as usual. Sum1 should design a smart search engines for programmers. It would go down a treat. Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/ Share on other sites More sharing options...
trq Posted June 8, 2010 Share Posted June 8, 2010 Single quotes need to be escaped when between single quotes or php thinks your ending your string. echo '[b]<?php if(function_exists(\'twit_connect\')){twit_connect();} ?>[/b]'; Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069401 Share on other sites More sharing options...
Novice@PHP Posted June 8, 2010 Author Share Posted June 8, 2010 Single quotes need to be escaped when between single quotes or php thinks your ending your string. echo '[b]<?php if(function_exists(\'twit_connect\')){twit_connect();} ?>[/b]'; It doesn't create an error now but nothing displays. Any suggestions thanks Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069410 Share on other sites More sharing options...
ignace Posted June 8, 2010 Share Posted June 8, 2010 You need eval Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069424 Share on other sites More sharing options...
trq Posted June 8, 2010 Share Posted June 8, 2010 You need eval I think the OP wants to actually output php code. Could well be wrong though... Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069430 Share on other sites More sharing options...
kenrbnsn Posted June 8, 2010 Share Posted June 8, 2010 You need to output "<" instead of "<" since the browser believes any string starting with a "<" is a tag and will try to use it. So use <?php echo '[b]<?php if(function_exists(\'twit_connect\')){twit_connect();} ?>[/b]'; ?> or <?php echo htmlentities("[b]<?php if(function_exists('twit_connect')){twit_connect();} ?>[/b]",ENT_QUOTES); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069434 Share on other sites More sharing options...
ignace Posted June 8, 2010 Share Posted June 8, 2010 You need eval I think the OP wants to actually output php code. Could well be wrong though... Following his logic it made me believe otherwise. I find it weird why he does not just do twit_connect(); as he clearly wants to show the twitter connect login. Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069435 Share on other sites More sharing options...
Novice@PHP Posted June 8, 2010 Author Share Posted June 8, 2010 You need eval I think the OP wants to actually output php code. Could well be wrong though... Following his logic it made me believe otherwise. I find it weird why he does not just do twit_connect(); as he clearly wants to show the twitter connect login. Oh I just picked the first piece of code I had pasted in my notepad. Need to dsipplay the google friend connect which doesn't disappear when logged in. Thanks every1 for your advice. I'm off to try the new suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069462 Share on other sites More sharing options...
Novice@PHP Posted June 8, 2010 Author Share Posted June 8, 2010 Tried suggestions and now it just outputs the code as plain text. Any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069466 Share on other sites More sharing options...
kenrbnsn Posted June 8, 2010 Share Posted June 8, 2010 What do you want to do? Your original explanation wasn't clear. Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069467 Share on other sites More sharing options...
Novice@PHP Posted June 8, 2010 Author Share Posted June 8, 2010 What do you want to do? Your original explanation wasn't clear. I want to echo the php code for execution. So when it echos it executes the PHP based on the condition if user is logged in. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069468 Share on other sites More sharing options...
kenrbnsn Posted June 8, 2010 Share Posted June 8, 2010 All you have to do is put the PHP code in the "if" block: <?php if ( is_user_logged_in() ) { if(function_exists('twit_connect')){twit_connect()}; } else { echo 'Welcome, visitor!'; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069470 Share on other sites More sharing options...
Novice@PHP Posted June 8, 2010 Author Share Posted June 8, 2010 All you have to do is put the PHP code in the "if" block: <?php if ( is_user_logged_in() ) { if(function_exists('twit_connect')){twit_connect()}; } else { echo 'Welcome, visitor!'; } ?> Ken Wow. That makes much more sense. Should have thought about that one. Hopefully this post ranks in the Google beast so others can benefit from it too. Thank you thank you thank you. Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069472 Share on other sites More sharing options...
premiso Posted June 8, 2010 Share Posted June 8, 2010 On a side note Google is fruitless as usual. Sum1 should design a smart search engines for programmers. It would go down a treat. Just because you are incompetent at Google, does not mean they need to make a "smarter" engine. What you really mean is they need to make a "dumbed" down version for people who do not understand how to search for what they want. As for what you are trying to do, I have no clue, your first statement says you just want to "echo" php to the page. Which has been shown to you. But now you say, when it echo's I want it to execute. Is this by change what you are wanting to do (Given that I have no clue what that twit_connect function does or returns this could be wrong as it is just guess work): EDIT: Content removed, given Ken posted what I was going to. Quote Link to comment https://forums.phpfreaks.com/topic/204180-output-php-with-php/#findComment-1069474 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.