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

  • SEARCH
  • Home
  • 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 7515385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:47:30+00:00 2026-05-30T00:47:30+00:00

I have problem with JSON, passing html code, I don’t understand because I escaped

  • 0

I have problem with JSON, passing html code, I don’t understand because I escaped with addslashes php function.

This is the JSON that fail:

With php JSON is valid:

<?php if(count($articles)): ?>
{"items":[
<?php foreach($articles as $key => $article): ?>
      <?php if($key==0  ):?>
      {
        "foto_g": "<?php echo $article->getRutafoto() ?>",
        "foto_th": "<?php echo $article->getRutathumb() ?>"

      }
    <?php else: ?>  
    ,
      {
        "foto_g": "<?php echo $article->getRutafoto() ?>",
        "foto_th": "<?php echo $article->getRutathumb() ?>"

      }
    <?php endif ?>  
<?php endforeach ?>
],
"nom_coleccio": "<?php echo $coleccio->getNom()?>"
,
"descripcio_coleccio": "<?php echo addslashes($coleccio->getDescripcio(ESC_RAW))?>"
}
<?php endif ?>  

And the result that have problem is:

{
"descripcio_coleccio": "<p>El delta de l\'Ebre ha estat l\'escenari d\'inspiraci&oacute; d\'aquesta col&middot;lecci&oacute;.</p>
<p>La l&iacute;nia de l\'horitz&oacute; i el color del paisatge materialitzats en alumini s\'uneixen per a crear volum en forma de joia.</p>"
}

When is the problem?

Thanks Regards

  • 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-30T00:47:32+00:00Added an answer on May 30, 2026 at 12:47 am

    You should use proper encoding functions if possible. In case of JSON you should use json_encode, even if just for particular values.

    But it would be easier if you collect the values in an array with associative keys and use json_encode only at the end:

    if (count($articles)) {
        $items = array();
        foreach ($articles as $key => $article) {
            $items[] = array(
                "foto_g"  => $article->getRutafoto(),
                "foto_th" => $article->getRutathumb()
            }
        }
        $data = array(
            "items"               => $items,
            "nom_coleccio"        => $coleccio->getNom(),
            "descripcio_coleccio" => $coleccio->getDescripcio(ESC_RAW)
        );
        echo json_encode($data);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem using JSON and arrays. Here is my code: while($row =
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I am having a problem passing a json string back to a php script
Json Problem : I have this formatted JSON { Table1:[ { TableName:LoadDistributor, Description:Distributor ,
I'm having a recursion problem in Javascript. I have some JSON that I'm passing
I have a problem with parsing a JSON result. This is what I get
I have a problem accessing JSON data. I'm new to JSON and jquery so
I have a problem passing in a complex type into a controller. Here is
I been trying to passing this value: // Content to submit to php Others
A] Problem summary: I have JSON data being returned from python to javascript. I

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.