Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7669487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:36:19+00:00 2026-05-31T15:36:19+00:00

When I am trying to echo json in php it returns \n \r \t

  • 0

When I am trying to echo json in php it returns \n \r \t . How I can remove them?

Here is my code:

            ob_start();
                $this->load->view('competition/template',$q);
                $content = ob_get_clean();
                $data['content'] = $content;

             echo json_encode($data);

And am getting:

</table>{"ok":1,"content":"<table>\r\n   <tr>\r\n\t    <td>Competitor name<\/td>\r\n\t    <td><input type=\"text\" name=\"competitor_name[2]\" \/><\/td>\r\n   <\/tr>\r\n   <tr>\r\n   <\/tr>\r\n   <tr>\r\n   <\/tr>\r\n   <tr>\r\n   <\/tr>\r\n<\/table>"}

This is the template.php file:

 <table>
   <tr>
        <td><?php echo $this->__('Competitor name');?></td>
        <td><input type="text" name="competitor_name[<?php echo $id?>]" /></td>
   </tr>

</table>

After str_replace or preg_repalce, am getting:

{"ok":1,"content":"<table>   <tr>    <td>Competitor name<\/td>    <td><input type=\"text\" name=\"competitor_name[1]\" \/><\/td>   <\/tr> <\/table>"}

Now my problem is \.

Thank you.

Ok I found the anwser. Here it is:

 $content = preg_replace("@[\\r|\\n|\\t|\\/|\\\"]+@", "", $content);

But am not sure why I was getting this problem .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:36:20+00:00Added an answer on May 31, 2026 at 3:36 pm

    Remove un-necessary whitespace from your content using:

    $content = preg_replace("@[\\r|\\n|\\t]+@", "", $content);
    $data['content'] = $content;
    echo json_encode($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Been reading up on php and json and am trying this piece of code
I am trying to convert some xml into a json object using PHP. This
I'm trying echo the contents of an object in a JSON format. I'm quite
im trying to echo mediaplayer embed code with IF statement. is there any way
I am trying to echo a result from xml into my html code form
I am trying to echo a javascript alert message in php but I am
I am trying to get the following code to work: if (isset($_POST['file'])){ if(file_exists($_POST['file'])){ echo
I've been trying to troubleshoot this, but can't find a good function that will
I'm trying to parse json data from google directions but can't seem to access
I'm trying to iterate in a JSON object that is returned from a PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.