Tuesday, August 7, 2007

JSON, php, and html forms

So I've been working on a data processing page that is hidden from the user, takes form data from an input page, processes the data, encodes the data using json in a new form, then auto submits the form to a new page. Here are a few helpful functions that got it working properly:

1. The json_encode() function in php doesn't escape some html special characters like quotes. It's helpful to wrap it with the function htmlspecialchars() so that it plays nice with your html.

2. php line breaks are '\r'. I had inadvertently included some line breaks in my string variables. To fix that problem use the trim() function.

No comments: