-1

I have this:

$rm = json_decode($room_list[0]['room']);

and i want to set a variable $string which include the result of echo of above variable.
For Example, IF:

echo json_decode($room_list[0]['room'];

echos: Lorem Ipsum <a href="www.google.com>GG</a>.

i want the string to be:

$string = 'Lorem Ipsum <a href="www.google.com>GG</a>.'

How can i do that?

cos nik
  • 386
  • 2
  • 14
  • 1
    Your question is unclear. `json_encode()` returns a value. You can either assign it to a variable, or echo it. Either way, you're assigning or echoing the same thing. – jbafford Jan 15 '16 at 23:58
  • 1
    You need a closing ) on your json_decode – David Jones Jan 15 '16 at 23:59
  • Not for me because i want a string to search in it with another process. My function get only string..not a variable.. – cos nik Jan 16 '16 at 00:00
  • Have you **tried** `echo $rm;`? – random_user_name Jan 16 '16 at 00:02
  • 1
    Your first line sets a PHP variable to the string. What's wrong with that? – Barmar Jan 16 '16 at 00:03
  • _"i want to set a variable $string which include the result of echo of above variable"_ Makes no sense. – Lightness Races in Orbit Jan 16 '16 at 00:04
  • Because after that $string = json_decode(..) the $string is not a string type. It's just a variable and i cant use it in my search function which accepts only string type.. – cos nik Jan 16 '16 at 00:05
  • 1
    You don't understand what you're talking about. Since you can echo it, it must be a string. What do you think `echo` is showing? – Barmar Jan 16 '16 at 00:06
  • 1
    There's no such thing as "just a variable". A variable is a name for a value, and the type goes with the value. Since `json_decode` is returning a string, and you assign that to a variable, the variable contains a string. – Barmar Jan 16 '16 at 00:07
  • All i am trying to do: When i copy/paste the json field from my db and set $string = 'content of json' then my search function works. If i have $string = content of json without the '' then it doesn't. – cos nik Jan 16 '16 at 00:11

1 Answers1

0

It looks like you're trying to do this: how to use JSON.stringify and json_decode() properly

So basically, take stripslashes(htmlspecialchars(JSON_DATA)) from that answer and put $rm = in front :)

Community
  • 1
  • 1
Lindsay Ryan
  • 433
  • 3
  • 9