Json_Encode + include/require + Flex + Wordpress PHP?


Json_Encode + include/require + Flex + Wordpress PHP?

我希望我的Wordpress用户登录,我可以将他们的用户名作为$变量放在Header.php中,然后在(jsontutorial.php)中使用json_encode将其调用到我的flex应用程序json_tutorial.mxml 上

这是我的简短版本。。。json_tutorial.php

    <?php
    require_once ('header.php');     //works without this, but doesn't work with this     
    $surname = '$variable';               // $variable = 'doe'; from header.php
    $p = array ('first_name' => john, 'last_name' => $surname);
    echo json_encode($p);            // prints out john doe
    ?>

Json_tutorial.mxml和Json_tautorial.php文件来自http://sadhas.wordpress.com/2009/11/26/flex-php-transmitting-data-using-json/#wrapper

我想知道为什么这不适用于Include或Require?

此外,我如何将从header.php到json_tutorial.php的变量调用为我的flex应用程序上的json_encode?

谢谢,我真的很感激你的帮助!

我遇到了同样的问题,我在echo json_encode(…)之前使用ob_clean()解决了它。

include("library1.php")
require("library2.php")
require_once("library3.php")
$p = array ('first_name' => john, 'last_name' => $surname);
ob_clean();
echo json_encode($p);