WordPress.org

Ready to get started?Download WordPress

Forums

Php in posts... (16 posts)

  1. XeroCool
    Member
    Posted 9 years ago #

    How can i have php in posts?......

  2. Minna
    Member
    Posted 9 years ago #

    That requires a plugin. See for example this or this. I use the latter one.

  3. XeroCool
    Member
    Posted 9 years ago #

    Yeh...Heres the problem:
    For Marks Hack (http://mark.scottishclimbs.com/archives/2004/07/02/running-php-in-wordpress-posts/), I get this error:
    Warning: Cannot modify header information - headers already sent by (output started at /home/xero1/public_html/wp-content/plugins/runphp.php:46) in /home/xero1/public_html/wp-admin/post.php on line 342
    In the comments, It said not to have no space after ending ?>. I made sure i didn't and i still get the error. For this plugin (http://blog.idahocline.com/index.php/archives/2004/05/27/php-tag-within-a-post/), I get:
    Parse error: parse error, unexpected $ in /home/xero1/public_html/my-hacks.php on line 8
    Please help :(!@

  4. XeroCool
    Member
    Posted 9 years ago #

    Gonna try now ;).

  5. XeroCool
    Member
    Posted 9 years ago #

    Ok. So i added this code:
    <?php
    function run_phpinpost($data) { $PHPTag = "phpcode"; $data = str_replace(array("rn","r"), "n", $data); while (false !== strpos($data, "< ".$PHPTag .">")) { $Before= substr($data, 0, strpos($data, "< ".$PHPTag.">")); $After = substr($data, strpos($data, "</>")+(strlen($PHPTag)+3)); $Evaluate = substr($data, strpos($data, "< ".$PHPTag.">")+(strlen($PHPTag)+2)); $Evaluate = substr($Evaluate,0,strpos($Evaluate, "</>")-1); $Evaluate = str_replace(array("’","‘"),"'", $Evaluate); $Evaluate = str_replace(array("”","“"),'"', $Evaluate); ob_start(); // run that data and grab what comes out eval($Evaluate); $data = $Before.ob_get_clean().$After; } // end of while return $data; } // end of run_phpinpost
    add_filter('the_content', 'run_phpinpost');
    // To add compatibility with earlier PHP version...(before 4.3.0)
    if (!function_exists("ob_get_clean")) {
    function ob_get_clean() { $ob_contents = ob_get_contents(); ob_end_clean(); return $ob_contents; }
    }
    ?>
    And get this now:
    Parse error: parse error, unexpected $ in /home/xero1/public_html/my-hacks.php on line 12

  6. XeroCool
    Member
    Posted 9 years ago #

    Can you do it please? I suck @ doing it :(

  7. XeroCool
    Member
    Posted 9 years ago #

    I tried inserting this:
    <phpcode>< ?php include ("wp-user.php") ; ?></phpcode>
    So it comes out in the post as:
    < ?php include ("wp-usen.php") ; ?>
    When i end it, It comes out as:
    <phpcode>< ?php include ("wp-user.php") ; ?></></phpcode>
    WTF?

  8. XeroCool
    Member
    Posted 9 years ago #

    Yep.
    I inserted: < phpcode ><?php include ("wp-user.php"); ?></ phpcode >

  9. Minna
    Member
    Posted 9 years ago #

    I edited my previous post and added that example code of < phpcode >include()</ phpcode > , meaning that you probably don't put the "< ? php" and "?>" part in the code but only the actual code. At least that's how the hack I use works

  10. XeroCool
    Member
    Posted 9 years ago #

    Tried this:
    < phpcode >include("wp-user.php"; )</ phpcode > And it comes out in bold:
    include("wp-usen.php"; )

  11. Minna
    Member
    Posted 9 years ago #

    it's supposed to be include("wp-user.php");

  12. XeroCool
    Member
    Posted 9 years ago #

    Then it comes out as in bold:
    include("wp-usen.php");

  13. Minna
    Member
    Posted 9 years ago #

    I'm stumped... Maybe some one more clever than me can help you out. Or maybe you could ask at IDaho Cline's blog...

  14. XeroCool
    Member
    Posted 9 years ago #

    *Bump*
    ok

  15. Mark (podz)
    Support Maven
    Posted 9 years ago #

    I think you should clearly clarify precisely what it is you want.
    As we discussed on #irc, you don't want the actual code to be shown.
    You want a script that when you enter something, it prints to the screen ? Yes ?
    How must this be different from what WP actually does ?
    (And please don't bump this soon: http://www.tamba2.org.uk/wordpress/forum/ )

  16. Minna
    Member
    Posted 9 years ago #

    I understand the need to be able to use php in a post (for example including a file etc.), but as I said, for me one of the plugins worked perfectly. And if you bumped me, I was half asleep and half watching Psycho III, it was, after all, way past midnight. (And I'm not a "committed" forum replier anyway.)
    What I was going to come ask after Psycho, XeroCool, was that you did enable myhacks in the options, didn't you?
    Which version of WP you use? If it's 1.2., maybe you should look into the Mark's hack because I have 1.2. (and it works for me, as stated) and the headers already sent error is probably easier to solve.
    There is another current thread on this which *just* disappeared off the latest discussions list but it's there... there was another plugin/hack link so check that out too
    *blabber* sorry

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.