-3

我在 wordpress 中使用了以下代码,但是在代码中调用图像时遇到了斜线问题。

global $wpdb;
    $data = array();
    echo $select = "SELECT * FROM `wp_posts` WHERE `post_title` LIKE '".$_REQUEST['term']."%' AND `post_type` = 'post' GROUP BY `post_title` "; 

    $results = $wpdb->get_results($select);
    foreach($results as $result)
    {
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $result->ID ), 'single-post-thumbnail' );
        $explode = explode('wp-content',$image[0]);

        print_r($image[0]);
        $pp = "<img src='".stripslashes($image[0])."'/>"; 



        $data[] = array(
            'label' => $pp.', '. $result->post_type ,
            'value' => $result->post_title
        );
    }        echo json_encode($data);
    flush();

我从阿贾克斯打来的电话。一切正常,但是当我调用图像路径时,路径将如下所示..

[{"label":"<img src='http:\/\/localhost\/sara\/wp-content\/uploads\/2013\/10\/parachute.jpg'\/>, post","value":"Pritesh Mahajan "}]

斜线自动添加。我如何解决这个问题。

4

2 回答 2

1

一切看起来都很好。这是 json_encode 功能。如果您在此字符串上进行 json_decode,您将获得带有不带斜线的字符串的对象。

于 2013-12-05T08:13:45.810 回答
-1

尝试

str_replace('\\','',$pp)

如果要从字符串中删除反斜杠$pp

于 2013-12-05T08:11:04.470 回答