Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm working on pricing script which uses data from local comparison shopping engine called zbozi.cz and I would like to ask you about how to get prices (and more) from it. However it returns me HTML file with javascript - and in the javascript codes there are needed data.

For example - I have a PHP array with data like this - http://pastebin.com/BjBtYMv4 - and there are about 10-20 codes like this in the array.

What do I need? Any library or something? I need to "translate" those javascript data into PHP array and after I'll save it into the MySQL database and process it with another script. It should be really fast because I need to process about 80 000 codes like this a day.

BTW - sometimes there are more / less whitespaces in this code, so the solution should be able to process everything.

Hope I have described my problem enough (my English restriction).

EDIT: I found this - Parsing Javascript (not JSON) in PHP - but it doesn't work for me :(

EDIT2: It works until "clickthruData" appear, so just one question - could you please make script which edit the code from paste bin to work with script in the EDIT above?

share|improve this question
    
"I have an PHP array with data like this - pastebin.com/BjBtYMv4"; - You one you linked is a JavaScript array mind you! Also, it's 100% JSONP encoding you'll need. Most modern browsers have encoding/decoding functions where libraries are not needed like the one you posted (2009). – MackieeE Oct 13 '13 at 19:46
up vote 1 down vote accepted

The Javascript you have posted looks like a JSON variable. Assuming you could cut off everything before an opening curly bracket { and a closing curly bracket }, you should be able to use PHP JSON functions to handle this.

share|improve this answer
    
ok, thank you! I'll try it and let you know – Northys Oct 13 '13 at 19:53
    
ok I tried it - pastebin.com/DCBgnsqe - but it returns NULL :( – Northys Oct 13 '13 at 19:56
    
Use de.php.net/json_last_error to find out why =) – MackieeE Oct 13 '13 at 20:01
    
it returned int 4 – Northys Oct 13 '13 at 20:04
1  
hehe, i've got it! used stackoverflow.com/questions/1554100/… and edited my string with $data = str_replace('},', ',', $data); =) – Northys Oct 13 '13 at 20:08
var opt = {'id': 'itemRow-0', 
           'url': 'http://www.videotech.cz/audio-video/dj-technika/.../', 
           'cp': '5B9DN0UD-qzuhuuvvKKZjg==' };

var encodedOpt = JSON.stringify( opt );

Then within your PHP file that was sent with the variable of encodedOpt,

<?php
   $decodedJson = json_decode( encodedOpt );
?>
share|improve this answer
    
I forgot to tell you it should work in the CLI mode. So I can't use JS. – Northys Oct 13 '13 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.