tags:

views:

80

answers:

2

I have following PHP code

 $val="<div id=user".$row['cid']." userid=".$row['cid']." class=innertxt><img src=images/images.jpg width=50 height=50><strong>".$uname."</strong><ul> <li>Email: ".$row['cemail']."</li> <li> <input type=checkbox id=select".$row['cid']." value=".$row['cid']." class=selectit /></li> </ul> </div>" ;

 $return["foo"] =$val;

 print json_encode($return);

but once i get result i get in following format ?

  <div id=user11 userid=11 class=innertxt><img src=images\/images.jpg width=50 height=50><strong>Ruby<\/strong><ul> <li>Email: [email protected]<\/li> <li> <input type=checkbox id=select11 value=11 class=selectit \/><\/li> <\/ul> 
<\/div>

why i am getting this \/ and how to solve it?

+1  A: 

Slashes should be escaped with a backslash, so the output is correct.

Try this:

var x = eval({ var: "<\/div>" });
alert(x.var);

It will produce the correct output. (</div>)

The interesting thing is, that you got a string, instead of an object. Are you sure that the code fragment is correct? Because it shoud be:

{ foo: <div id=user11 userid=11 class=innertxt><img src=images\/images.jpg width=50 height=50><strong>Ruby<\/strong><ul> <li>Email: [email protected]<\/li> <li> <input type=checkbox id=select11 value=11 class=selectit \/><\/li> <\/ul> 
<\/div> }

Are you sure you wrote json_encode($return), instead of json_encode($return['foo'])?

WishCow
+1  A: 

try stripslashes

like

        print stripslashes(json_encode($return));

hope this will work....