When valid JSON data return NULL resolved with php_decode!

I was develop application which support json, and my valid json return null when i was trying to decode with php function (json_decode())

this is problem make me headache.

 

VALID JSON

You have to sure that your JSON data are valid, to make you easier you can find json validator online at google.  Copy Paste your code to online validator and let’s see if your JSON are valid or not.

In my case I use http://jsonlint.com/ and http://jsonformatter.curiousconcept.com/

Opppsss….!!!

My JSON are valid but still return null with PHP.

 

FIND ERROR

If you check with validator  there no error then you have to know what PHP said :

use following code to check it up in your code


json_decode( $json_data, true, 9 )
$json_errors = array(
JSON_ERROR_NONE => 'No error has occurred',
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'Syntax error',
);
echo 'Founded Error  : ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL;

after you try this you may know what php say about your json code and you can fix it.

 

In my case as I mention above , php said error. that’s funny becuase online validator said data are valid.

 

CLEAN JSON DATA

cause of my case I create function to clean special character like space \n \t etc

after i use it wow… finally my json data are valid and not return NULL anymore.

here is the function in php


function json_clean($string){

function clean_json($string) {
// for end of line (or begining)
$string = trim($string);
// from everywhere
$string = str_replace("\n", "", $string);
$string = str_replace("\r", "", $string);
return $string;
}

}

 

—————————————————————————

in another occasion you may face with diffrent problem with me

fell free to ask it with form bellow, we can find solution together.

Tags: ,

Linux Date Time, How to change date time in Linux Shell

I have two server and little bit make me headache, because of different time in another server

surf in the Internet Finally found how to change date time in linux

 

simply to see what date or time now in server you can use command DATE, as showed below in example:


root@tempe:~# date
Mon Nov 14 12:12:26 ICT 2011

 

To change date put this argument on DATE command, for example if you want to change date time to November 12, 2011 use following option :


root@kwetiau:~# date +%Y%m%d -s "20111114"
20111114

and then use date command to see, of course you have made change already.

 

with same command you can use another argument to change time, see example below how to change time to 12:08:10 in current date:


root@kwetiau:~# date +%T -s "12:08:10"
12:08:10

yup right you have made change time

 

change date time in on command? of course it is possible, use this command :


root@kwetiau:~# date -s "14 NOV 2011 12:30:00"

this command will change date and time to Nov 14, 2011 12:30:00

 

hope this usefull for you…

 

http://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/

 

Repair MySQL Database from Shell or Commandline

Simple way how to repair your database from command line or shell

 

simply you can use this command….

 


root@tahu:~# mysqlcheck -u root -p --all-databases --repair

// WAIT UNTIL FINISH

Tags: ,

My Best Collection of jquery navigation

Focus on my project to create a company profile website about scaffolding for marine. So I interest to improve good looking  menu navigation for this site. jQuery Navigationi type that keyword on Google and the results give a lot of inspiration to my menu.

here is my best Choice

15 Really Amazing jQuery Navigation Menu – Tutorials & Scripts

55 Super Powerful jQuery Navigation and Menu Plugins

So interest to see all of menu navigation in link  above, dig deep and explore….

Hope you can found beautiful pearl there….

 

Good Luck!!!!

Tags: , ,

How to Convert Data to Different Type in MySQL

I have new project to create some kind like book stored information for elementary school at putera batam.

Faced on query how to convert integer to decimal data type. To do this we can use CAST function (this only work if you have MySQL 5+)

here is the syntax

CAST expression AS new_data_type

You can see this example  :


$sql = "SELECT CAST( stock AS DECIMAL(5,2)) from inventory  ";

In code above  stock is integer data type but when you use CAST will give result Decimal.

Of course you can use different data type depend on your need.

that’s it…

^_^

 

 

Tags: ,