Jump to content

Output PHP with PHP?


Novice@PHP

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.  :D

 

Thank you thank you thank you.

Link to comment
Share on other sites

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.

 

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.