remove slashes from the string in php

1.4k views Asked by At

I have used below code in wordpress but i am facing slashes problem while call images in the code.

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();

I have called from Ajax. Every things is working fine but when i call images path path will look like below..

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

Slashes auto add. how i resolve this.

2

There are 2 answers

0
KryDos On BEST ANSWER

All looks fine. This is json_encode feature. If you make json_decode on this string you'll get the object with strings without slashes.

0
Maarkoize On

Try

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

if you want to remove Backslashes from the string $pp