Because PHP 5.1.6. doesn't include the json_decode function, I've downloaded an alternative and included it myself. But for some reason it's really really slow.
This one for example I tried:
http://mike.teczno.com/JSON/JSON.phps
I have tried a few other alternatives.
Does somebody know a better alternative to decode json faster or is it impossible in PHP < 5.2
Related
I have been developing on my test server which is PHP 5.5 and used an xpath query of this structure:
$year = $this->xml->xpath("//field[#label='Year']");
$year[0]['value'];
And all works perfect but as sson as I move it to the live server which is php 5.4 all my xpath queries would break. I am just wondering if anyone out there could give me some insight as to why or how to overcome this problem without upgrading php. I am guessing something is not enabled on my live site other than xpath that should be.
Compare versions of SimpleXml on server and the testing environment. (use phpinfo(); for that)
I would also advice you to step over to DOMDocument which I have noticed is actually more reliable. Otherwise please post your original xml so we can take a look for possible problems.
I was asked to help getting a website that was running with 5.2 php code, to work on a 5.3 php server. The site is big, and I can't see the errors that would appear normally when a site isn't working.
I've tried to use the Search and replace function that Dream Weaver has, and simply use it all over the website. But the problem is that I only want to replace functions in PHP documents, and not in js files. When i use Search and replace, in Dreamweaver, it overwrites the js files aswell, and that would cause more errors. Because there's A LOT of files that i have to go through, it would take me a lot of time if i had to go through it manually.
I figured this must be a problem that a lot of firms experiance, so there must be ways to handle this without it being a bigger hassle.
Anybody out there who could help me out ? Any help is much appreciated!
Regards,
Mathias
Check out the official guide about Migrating from PHP 5.2.x to PHP 5.3.x
most existing PHP 5 code should work without changes, but make sure error-reporting is enabled to get some idea of what is going wrong .
I would recommend the use of sed from command line. It is most likely the fastest and most powerful find/replace utility available for LAMP developers.
http://www.grymoire.com/Unix/Sed.html
Dont worry about it! If your code works in php->5 for the most part it will work just fine. 5.3 offers a plethora of options but no doubt your not using them.
I am running PHP version 5.1.6 currently, but I would have an application which makes pretty heavy use of the json_encode and json_decode functions, as such, I would like to add these functions to my server's install of PHP (as these functions only ship with PHP versions PHP 5.2 +)
What is the best way of doing this. I'm not too down with the whole Terminal approach so if there was another way that would be great
Many thanks in advance
If you're unable to upgrade, use PEAR's Services_JSON. It works as of PHP 4.3 so you should be fine.
Maybe you should put somewhere in the root of your application a call to a checker function that does function_exists() for a couple of your needed function and if not stops the execution to prevent unwanted results.
Im building a codeigniter app which uses json_encode to provide ajax data in many places... today I learned that the server has php 5.1.6 which doesnt support this method (or json_decode).. what can I do?? please help.
There is an emulation of json_encode() in upgradephp. Just include() that script, and you don't need to rewrite anything.
As alternative you can use PEAR::PHP_Compat. IIRC it has an emulation of that too.
(There are further alternative implementation floating around; but often object-style and not as fast and designed to emulate the core function.)
You can set them up with auto_prepend_file= even. If you just want the JSON extension enabled, there are other sources of course.
You could use Services_JSON if CodeIgniter can use it instead of PHP 5.2's json_* functions - I know Zend_Framework has Zend_Json which uses json_* functions if available, otherwise it uses its own implementation in userland PHP code as a fallback.
Of course, if you have access to the server to compile PHP, you could try the extension or upgrading to PHP 5.2 (a better solution).
EDIT: I would take the route of compatibility layers as mentioned above.
The json_decode is added since (PHP 5 >= 5.2.0, PECL json >= 1.2.0), it is supported in your version too, you should give it a try :)
I needed json_encode and json_decode for jquery grid.
I tried upgradephp but json_encode didnt seem to work with jquery grid so I deleted that function from the file and added this one. json_decode seems to work just fine though.
In fact, 5.1.6 supports json_decode and json_encode, but they can be a bit weird. As in, if you feed it invalid JSON, such as if you have a blank key, it will die without any warnings or errors. But I use json_encode and json_decode every day in a 5.1.6 environment. It's totally possible.
I am passing a json encoded string from javascript to a php file on the server via ajax. on my online server this works fine. but locally, it does not.
There are a few differences in the php installs in the 2 places. minor ones. both are php4. the install locally is actually a newer php4.
I'm trying to track down why this is happening. It looks like the json parsing on the server side with the pear servies_json (json.php), isn't parsing correctly. It manages the first brackets, but then it stops there, and all the internal data is lost?
Is there a php plug in or something that I need to install that keeps this from happening. A setting switch? Thanks for any help.
json_decode() should be used on the server-side to decode the JSON object, it should work fairly consistently. Its sister function json_encode() is equally good for encoding an array/object to a JSON string which can be echoed in your javascript.
Both functions require php 5, for php 4 you can check out this code.