Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从php显示html_Php_Wordpress - Fatal编程技术网

从php显示html

从php显示html,php,wordpress,Php,Wordpress,这与wordpress和php有关。我有一个从json中获取名称数组的函数。对于我循环使用的每个名称,它都会创建一个div,其中包含名称和图像。然后将该div连接到一根柱子上,并显示在前端。问题是由于404错误,图像无法正确显示。当我查看图像源时,图像的路径如下所示: 很明显,这条路已经断了,所以404是有意义的。似乎php正在试图逃避一些引用,所以我尝试用str_替换来删除它,作为一个暗中拍摄,我还尝试了html_实体_解码。还尝试了一个绝对路径到我的图像,但也没有工作。当我刷新页面时,图像

这与wordpress和php有关。我有一个从json中获取名称数组的函数。对于我循环使用的每个名称,它都会创建一个div,其中包含名称和图像。然后将该div连接到一根柱子上,并显示在前端。问题是由于404错误,图像无法正确显示。当我查看图像源时,图像的路径如下所示:

很明显,这条路已经断了,所以404是有意义的。似乎php正在试图逃避一些引用,所以我尝试用str_替换来删除它,作为一个暗中拍摄,我还尝试了html_实体_解码。还尝试了一个绝对路径到我的图像,但也没有工作。当我刷新页面时,图像看起来很好,所以我认为这与不立即编译有关?如果这是真的,我如何在不刷新页面的情况下使其正确显示

function test_function() {
  if ( isset($_POST) ) {

        $nameData = $_POST['nameData'];

        //Strip any double escapes then use json_decode to create an array.
        $nameDecode =  json_decode(str_replace('\\', '', $_POST['nameData']));


        //loop through names array and create a container for each
        $html_string = "";

       foreach ($nameDecode as $keyIndex => $name) {
            $html_string .= '<div class="team-container team-container--inline col col--md-2 col--lg-2 col--xl-2"><img src="'. get_template_directory_uri() .'/images/baseball/team' . $keyIndex . '.jpg"> <p>'.$name.' <p /></div>';

       }

        echo ( $html_string);

        //$html_final = str_replace('\\', '', $html_string);
        $html_final = html_entity_decode($html_string);

        // update teams post
        if($html_string != "") {
          $my_post = array(
            'ID'           => 9,
            'post_content' => $html_final,
        );

        // Update the post into the database
          wp_update_post( $my_post );
        } else {
          echo 'html string is empty!';
        }


    }
  die();
}
功能测试\u功能(){
国际单项体育联合会(国际单项体育联合会){
$nameData=$_POST['nameData'];
//去掉任何双转义,然后使用json_decode创建一个数组。
$nameDecode=json\u decode(str\u replace('\\','',$\u POST['nameData']);
//循环遍历names数组并为每个数组创建一个容器
$html_string=“”;
foreach($name解码为$keyIndex=>$name){
$html_string.=''.$name.'

'; } echo($html_字符串); //$html\u final=str\u replace('\\',''$html\u字符串); $html\u final=html\u entity\u decode($html\u string); //更新团队帖子 如果($html\u字符串!=“”){ $my_post=数组( 'ID'=>9, “发布内容”=>$html\u最终版, ); //将帖子更新到数据库中 wp_update_post($my_post); }否则{ echo“html字符串为空!”; } } 模具(); }


如果要删除斜杠,请尝试此操作

$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);


 $nameData = $_POST['nameData'];
$stringObject = json_decode(stripslashes($nameData));
对于json编码

json_encode($html_string, JSON_UNESCAPED_SLASHES);

谢谢你的回答。我担心$html\u最终会被发布。然而,我不知道条纹斜杠,我玩了一点。文件路径仍然显示相同的内容。但我确实注意到,当我首先对数据使用
json\u encode
时,它显示了我想要的字符串,然后是
stripslashes
。因此,如果
$html\u final=stripslashes(json\u encode($html\u string))
,我如何正确地将其添加到
post\u内容中?或者,我必须以某种方式删除$html\u字符串中转义的双引号;