Sponsored Content
Top Forums Web Development Notes with Ravinder on Badging System Development Part II Post 303028354 by RavinderSingh13 on Saturday 5th of January 2019 05:59:57 AM
Old 01-05-2019
Quote:
Originally Posted by Neo
Ravinder,
Please write a PHP function to parse the $color[] array and create the string(2) to append in the badge alert text.
Hint: You need to read a $serialized_badges JSON string (which we will get from the user table and convert it to a PHP array using json_decode() then perhaps a foreach() loop to compare against the current $color[] array.
Or, you can do all this in Javascript by storing the badge[] js array serialized in localstorage, which is how I would do it I think.... No reason to do this in PHP, so I think best to do in Javascript.
Sorry Neo I didn't get it Smilie if you could give me little more scenario like sample input and expected output then I will try my BEST to write it. Sorry I am that good like you in coding to be honest.

Thanks,
R. Singh
 

3 More Discussions You Might Find Interesting

1. What is on Your Mind?

New Badging System - Badges Prototype Beta 1 (Badges Only)

Today I mapped out the new badging system using FA icons, Beta 1 in no particular order except a 6 x 8 grid: https://www.unix.com/members/1-albums215-picture991.png The prototype HTML code for this layout: <style> .fa-badge-grid { font-size: 1.5em; } .row { ... (38 Replies)
Discussion started by: Neo
38 Replies

2. What is on Your Mind?

Status of Badging System - Beta 1

Dear All, Here is the current status of the badging system: The Beta 1 phase of the new badging system is close to completion. 42 prototype badges have been "allocated" 6 prototype badge slots are held in reserve The "alert you have new badges" prototype is running and is currently... (4 Replies)
Discussion started by: Neo
4 Replies

3. What is on Your Mind?

Badging System: UNIX.COM Bug Hunter Badge (New)

I have moved the bug badge out of reserve and into the main stream. Basically, I will assign a color level like the others, based on who has made a good actionable bug report for UNIX.COM. "Good" means screenshots, links, and even details from web dev tools our the HTML source code. So far,... (0 Replies)
Discussion started by: Neo
0 Replies
JSON_LAST_ERROR(3)							 1							JSON_LAST_ERROR(3)

json_last_error - Returns the last error occurred

SYNOPSIS
int json_last_error (void ) DESCRIPTION
Returns the last error (if any) occurred during the last JSON encoding/decoding. PARAMETERS
This function has no parameters. RETURN VALUES
Returns an integer, the value can be one of the following constants: JSON error codes +----------------------------+---------------------------------------------------+ | Constant | | | | | | | Meaning | | | | | | Availability | | | | +----------------------------+---------------------------------------------------+ | | | | JSON_ERROR_NONE | | | | | | | No error has occurred | | | | | | | | | T{ | | | | | | JSON_ERROR_DEPTH | | | | | | The maximum stack depth has been exceeded | | | | | | | | | T{ | | | | | | JSON_ERROR_STATE_MISMATCH | | | | | | Invalid or malformed JSON | | | | | | | | | T{ | | | | | | JSON_ERROR_CTRL_CHAR | | | | | | Control character error, possibly incorrectly | | | encoded | | | | | | | | | T{ | | | | | | JSON_ERROR_SYNTAX | | | | | | Syntax error | | | | | | | | | T{ | | | | | | JSON_ERROR_UTF8 | | | | | | Malformed UTF-8 characters, possibly incorrectly | | | encoded | | | | | | PHP 5.3.3 | | | | | | | | JSON_ERROR_RECURSION | | | | | | | One or more recursive references in the value to | | | be encoded | | | | | | PHP 5.5.0 | | | | | | | | JSON_ERROR_INF_OR_NAN | | | | | | | One or more NAN or INF values in the value to be | | | encoded | | | | | | PHP 5.5.0 | | | | | | | |JSON_ERROR_UNSUPPORTED_TYPE | | | | | | | A value of a type that cannot be encoded was | | | given | | | | | | PHP 5.5.0 | | | | +----------------------------+---------------------------------------------------+ EXAMPLES
Example #1 json_last_error(3) example <?php // A valid json string $json[] = '{"Organization": "PHP Documentation Team"}'; // An invalid json string which will cause an syntax // error, in this case we used ' instead of " for quotation $json[] = "{'Organization': 'PHP Documentation Team'}"; foreach ($json as $string) { echo 'Decoding: ' . $string; json_decode($string); switch (json_last_error()) { case JSON_ERROR_NONE: echo ' - No errors'; break; case JSON_ERROR_DEPTH: echo ' - Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: echo ' - Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: echo ' - Unexpected control character found'; break; case JSON_ERROR_SYNTAX: echo ' - Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'; break; default: echo ' - Unknown error'; break; } echo PHP_EOL; } ?> The above example will output: Decoding: {"Organization": "PHP Documentation Team"} - No errors Decoding: {'Organization': 'PHP Documentation Team'} - Syntax error, malformed JSON Example #2 json_last_error(3) with json_encode(3) <?php // An invalid UTF8 sequence $text = "xB1x31"; $json = json_encode($text); $error = json_last_error(); var_dump($json, $error === JSON_ERROR_UTF8); ?> The above example will output: string(4) "null" bool(true) SEE ALSO
json_last_error_msg(3), json_decode(3), json_encode(3). PHP Documentation Group JSON_LAST_ERROR(3)
All times are GMT -4. The time now is 08:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy