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 6892085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:29:26+00:00 2026-05-27T06:29:26+00:00

i encode the user entred testarea content with json_encode here is how it storred

  • 0

i encode the user entred testarea content with json_encode
here is how it storred in mysql (there is a return to line after “aaa”)

{"content":"aaa
bbb"}

now when i get the the content from database and trying to decoded it using json_decode, i get NULL for this, instead of what expected.

what wrrong? a bug in PHP?

EDIT 1: more details

$data =array('content'=>$textareaText);
$addres_insert = "INSERT INTO `rtable` (`data`) VALUES ('".json_encode($data)."');";
$rows = mysql_query($addres_insert);

then to get the content

$query = "SELECT * FROM  `rtable` WHERE id =  '".$id."'";
        $rows = mysql_query($query);
    if ( $rows ){
        $row = mysql_fetch_array($rows);
        $res['data'] = json_decode($row['data']);//i tryed substr($row['data'],3) but didn't work
    }
  • 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-27T06:29:26+00:00Added an answer on May 27, 2026 at 6:29 am

    JavaScript and JSON do not allow line returns to be contained within a string. You need to escape them.

    json_encode() should escape them automatically for you.

    Here is the output of my playing with your JSON code supplied on the PHP interactive shell:

    php > $json = '{"content":"aaa
    php ' bbb"}';
    php > var_dump(json_decode($json, true));
    NULL
    

    As you can see when I escape your line return it works just fine:

    php > $json = '{"content":"aaa\n bbb"}';
    php > var_dump(json_decode($json, true));
    array(1) {
      ["content"]=>
      string(8) "aaa
     bbb"
    }
    

    This is also further discussed in a previous question relating to a similar problem: Problem when retrieving text in JSON format containing line breaks with jQuery

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a standard way to encode the user location (country, state/region, town), so
I generally HTML-encode any user generated content that I render on my website, so
Simple question that keeps bugging me. Should I HTML encode user input right away
I currently use, base64_encode() to encode a user's password, this works well because it
I need to encode a 100KB+ string as base64 in VBA. Are there any
<%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl %> <% if (Request.IsAuthenticated) { %> Welcome <b><%= Html.Encode(Page.User.Identity.Name) %></b>!
I've been trying to Base64 encode image data from the user (in this case
Here's my problem: I have a textarea where the user can enter whatever he
Html.Encode seems to simply call HttpUtility.HtmlEncode to replace a few html specific characters with
Does the SCN itself encode a timestamp or is it a lookup from some

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.