Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating strings in PHP for JSON output

A. I store tags in a database which are user input.

B. For views, a group of these tags are then fetched with a query and concatenated.

C. I iterated this format and print each tag in the view.

For part B I create a JSON array with the concatenation in the query. But now I'm thinking it might be worthwhile to pick an even more lightweight format than JSON. My reasoning is it would make it simpler to validate the user tags coming into the database.

If I were to choose one delimiter, say , to identify tokens would the only validation needed be disallowing this character for tags?

like image 446
el_pup_le Avatar asked Dec 22 '25 10:12

el_pup_le


1 Answers

But now I'm thinking it might be worthwhile to pick an even more lightweight format than JSON.

Why do you think so? More often than not, using JSON simplifies things a lot both on the frontend and the backend because you can do a json_decode in PHP and just an eval JSON.parse in Javascript and then your JSON data will be translated to native objects in the respective language which you can then manipulate easily. So I would recommend you stick to JSON.

like image 185
ErJab Avatar answered Dec 23 '25 23:12

ErJab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!