Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
how to remove backslash and slash characters from JSON in PHP (wordpress) not with js

I want to remove the backslash from JSON. however i have tried multiple ways using str_replace, stripslashes method and json_decode($response,JSON_UNESCAPED_SLASHES); but i still not able to remove the backslash from JSON Content . Althought when i output the json content in js i used let str = item.replace(/\/g, ''); to remove it. however i want to do it only on php. i dont want to output it on js. i will past my php code and js . im the code below im doing two api calls at the same time.

$facebookID = get_option( 'facebook_page_id' );
$instagramID =  get_option( 'instagram_profile_id'  );
$instagramName = get_option('instagram_profile_name');



function sns_display_post_action(){

  $optionArray = array(
  
    CURLOPT_USERAGENT        => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0',//Pick your user agent.
    CURLOPT_RETURNTRANSFER   => TRUE,
    CURLOPT_TIMEOUT          => 10
  
  );
  $data = [];
  $access_token = get_option('access_token');
  $limitpost = get_option( 'post_count_number' );

 
 $data1 =  "https://graph.facebook.com/v14.0/$instagramID?fields=business_discovery.username($instagramName){id,name,profile_picture_url,media.limit($limitpost){id,owner,username,media_type,permalink,caption,timestamp,media_url,children{media_url}}}&access_token=$access_token";
 $data2 =  "https://graph.facebook.com/v14.0/$facebookID?fields=id,about,name,picture{url},posts.limit($limitpost){id,created_time,message,permalink_url,attachments{media_type,type,media,url,subattachments,unshimmed_url,description},full_picture}&access_token=$access_token";
 
  //Create an array of your urls.
  $urlArray = array(
  
     $data1,
     $data2
  
  );
  function str_replace_json($search, $replace, $subject){
    return json_decode(str_replace($search, $replace,  json_encode($subject)));

}

  $nThreads = 2;
  
  //To use run the function.
  $results = multi_thread_curl($urlArray, $optionArray, $nThreads);
  $content = wp_send_json($results);
  echo $content;
   



}

add_action( 'wp_ajax_sns_post_action', 'sns_display_post_action');
add_action( 'wp_ajax_nopriv_sns_post_action', 'sns_display_post_action');

and this is the js code below. here im using fetch API. show the content.

  let params =  new FormData();
params.append("action", sns_show_options.action);
params.append("nonce", sns_show_options.nonce);

fetch(sns_show_options.api,{
  method:'POST',
  body:params,
} )
 .then(response => response.json())
 .then(s =>console.log(s))

I cant show the whole content because of security reason , but the content on console.log is show like below.

"{\n "id": "14",\n "about": "i will make some videos and share my hard work",\n "name": "testname",\n "picture": {\n

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda