PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 20, 2022

[FIXED] How to remove double slashes (\\r\\n\\r\\n) in str_replace

 November 20, 2022     php, preg-replace, replace, str-replace, wordpress     No comments   

Issue

I'm trying to remove <p> and </p> from my JSON rest API output. I did the below but the output it gives me has double slashes like \\r\\n\\r\\n. So how do I change the double slashes to single?

Here's my code

//Remove <p> HTML element and replace with line breaks
$return = str_replace('<p>', '', $return);
$return = str_replace('</p>', '\r\n\r\n', $return);
        
//Output the data in JSON format without escaping the URL slashes
wp_send_json($return, 200, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);

Or can the above me more efficient if I use preg_replace?


Solution

all is okay you Just need to use json_deocde in front side or where you want to print the result



Answered By - Salman ansari
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing