WordPress.org

Support

Support » How-To and Troubleshooting » Php in posts…

Php in posts…

Viewing 15 replies - 1 through 15 (of 15 total)
  • That requires a plugin. See for example this or this. I use the latter one.

    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 :(!@

    Gonna try now ;).

    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

    Can you do it please? I suck @ doing it 🙁

    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?

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

    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

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

    it’s supposed to be include(“wp-user.php”);

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

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

    *Bump*
    ok

    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/ )

    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

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Php in posts…’ is closed to new replies.