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
UNSERIALIZE(3)								 1							    UNSERIALIZE(3)

unserialize - Creates a PHP value from a stored representation

SYNOPSIS
mixed unserialize (string $str) DESCRIPTION
unserialize(3) takes a single serialized variable and converts it back into a PHP value. PARAMETERS
o $str - The serialized string. If the variable being unserialized is an object, after successfully reconstructing the object PHP will automatically attempt to call the __wakeup() member function (if it exists). Note unserialize_callback_func directive It's possible to set a callback-function which will be called, if an undefined class should be instantiated during unserial- izing. (to prevent getting an incomplete object "__PHP_Incomplete_Class".) Use your php.ini, ini_set(3) or .htaccess to define ' unserialize_callback_func'. Everytime an undefined class should be instantiated, it'll be called. To disable this feature just empty this setting. RETURN VALUES
The converted value is returned, and can be a boolean, integer, float, string, array or object. In case the passed string is not unserializeable, FALSE is returned and E_NOTICE is issued. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.6.0 | | | | | | | Manipulating the serialised data by replacing C: | | | with O: to force object instantiation without | | | calling the constructor will now fail. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 unserialize(3) example <?php // Here, we use unserialize() to load session data to the // $session_data array from the string selected from a database. // This example complements the one described with serialize(). $conn = odbc_connect("webdb", "php", "chicken"); $stmt = odbc_prepare($conn, "SELECT data FROM sessions WHERE id = ?"); $sqldata = array($_SERVER['PHP_AUTH_USER']); if (!odbc_execute($stmt, $sqldata) || !odbc_fetch_into($stmt, $tmp)) { // if the execute or fetch fails, initialize to empty array $session_data = array(); } else { // we should now have the serialized data in $tmp[0]. $session_data = unserialize($tmp[0]); if (!is_array($session_data)) { // something went wrong, initialize to empty array $session_data = array(); } } ?> Example #2 unserialize_callback_func example <?php $serialized_object='O:1:"a":1:{s:5:"value";s:3:"100";}'; // unserialize_callback_func directive available as of PHP 4.2.0 ini_set('unserialize_callback_func', 'mycallback'); // set your callback_function function mycallback($classname) { // just include a file containing your classdefinition // you get $classname to figure out which classdefinition is required } ?> NOTES
Warning FALSE is returned both in the case of an error and if unserializing the serialized FALSE value. It is possible to catch this special case by comparing $str with serialize(false) or by catching the issued E_NOTICE. Warning Do not pass untrusted user input to unserialize(3). Unserialization can result in code being loaded and executed due to object instantiation and autoloading, and a malicious user may be able to exploit this. Use a safe, standard data interchange format such as JSON (via json_decode(3) and json_encode(3)) if you need to pass serialized data to the user. SEE ALSO
serialize(3), Autoloading Objects, unserialize_callback_func, __wakeup(). PHP Documentation Group UNSERIALIZE(3)
All times are GMT -4. The time now is 05:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy