Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How can I get json string from this array:
json
$test['author'] = '<p>Written By: <a href="">Someone</a></p>'; echo json_encode($test); // removed erroneous question mark
[in real, this string came from sql select query.]
sql select query
Any ideas?
json_encode
json string from array
Based on Marc B's comment what will probably fix this for you is:
echo htmlspecialchars(json_encode($test));
That way your <p> tags (and any others) will be changed to <p> and such won't be interpreted by your browser as HTML.
<p>
<p>
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
json_encodeand it'll work fine.json string from array?