0
我使用了一个websocket服务器,它通过json_encode发送数据(在本例中为$ html)到我的客户端。 (index.php)传入的数据通过jQuery附加到内容div。包含并使用来自JSON响应的PHP代码
所以基本上我需要的是在我的index.php中回显来自websocket服务器的php变量。
换句话说:
我如何可以包括一个JSON响应我的代码作为PHP代码可以在其他方面在这个文件中使用?
(真的很难解释这个问题)
<!-- index.php -->
<?php
$usersname = 'John';
?>
<div id="content"></div>
<!-- server.php -->
<?php
ob_start();
include 'file.php';
$html = ob_get_clean();
?>
<!-- file.php -->
<h1>Hello <?php echo $username ?></h1>