How to randomize json - php

I have a randquotes.json file
{
"author": "William Shakespeare",
"quotes": "A brave flea is a flea that can dare to get its breakfast on the lips of a lion."
},
{
"author": "Winston Churchill",
"quotes": "We live with what we get, but we bring life to what we give."
},
{
"author": "Wolfgang von Gothe",
"quotes": "Knowledge is not enough, we must practice it. Intention is not enough, we must do it."
}
Then I want "author" and "quotes" to be generated randomly with php
How?
thanks for help

Assuming you actually have valid a JSON string...
Convert the json to a PHP datatype using json_decode()
find out how large the array is
generate a random number between 0 and array size
Return that array occurance, I did that as a json string again using json_encode()
$json_string = '
[
{
"author": "William Shakespeare",
"quotes": "A brave flea is a flea that can dare to get its breakfast on the lips of a lion."
},
{
"author": "Winston Churchill",
"quotes": "We live with what we get, but we bring life to what we give."
},
{
"author": "Wolfgang von Gothe",
"quotes": "Knowledge is not enough, we must practice it. Intention is not enough, we must do it."
}
]';
$arr = json_decode($json_string);
// How big is the array
$max = count($arr) -1;
$rand_idx = rand(0, $max);
echo json_encode($arr[$rand_idx]);

Related

is it possible to use foreach in foreach in codeigniter

Here is my function - I get an error.
In variable $data['stars'] I got maximum numbers of stars with is invalid
I want correct stars from database because actually stars table are different so that's why.
Is it possible to get stars from another table in this foreach to get accurate value?
public function dbmovies()
{
$this->db->order_by("videos_id", "desc");
$this->db->where(array('publication' => 1, 'is_tvseries' => 0));
$query = $this->db->get('videos');
//get stars
foreach ($query->result() as $key => $value) {
$this->db->where_in('star_id', $value->stars);
$queryStars = $this->db->get('star');
$stars=array();
foreach ($queryStars->result() as $star) {
$stars[] = $star->star_name;
$starone = implode(", ", $stars);
}
$data['videoId'] = $value->videos_id;
$data['imdbid'] = $value->imdbid;
$data['title'] = $value->title;
$data['description'] = $value->description;
$data['duration'] = $value->runtime;
$data['views'] = $value->total_view;
$data['stars'] = $starone;
$alldata[] = $data;
}
$get['data'] = $alldata;
echo json_encode($get, JSON_PRETTY_PRINT);
}
And tge output I get like this
{
"data": [
{
"videoId": "47",
"imdbid": "tt2935510",
"title": "Ad Astra",
"description": "<p>The near future, a time when both hope and hardships drive humanity to look to the stars and beyond. While a mysterious phenomenon menaces to destroy life on planet Earth, astronaut Roy McBride undertakes a mission across the immensity of space and its many perils to uncover the truth about a lost expedition that decades before boldly faced emptiness and silence in search of the unknown.<\/p>",
"duration": "123 Min",
"views": "2",
"stars": "Brad Pitt"
},
{
"videoId": "45",
"imdbid": "tt8243160",
"title": "Hacker",
"description": "<p>13-year-old Benjamin discovers that his mother didn\u2019t die in an accident as he was led to believe. The trail leads to high-ranking officials in the Danish Secret Service. \"Trust no one!\", he is told.<\/p>",
"duration": "96 Min",
"views": "93",
"stars": "Brad Pitt, Rumle Krs"
},
{
"videoId": "44",
"imdbid": "tt7131622",
"title": "Once Upon a Time... in Hollywood",
"description": "<p>A faded television actor and his stunt double strive to achieve fame and success in the film industry during the final years of Hollywood's Golden Age in 1969 Los Angeles.<\/p>",
"duration": "161 Min",
"views": "71",
"stars": "Brad Pitt, Rumle Krs, Leonardo DiCaprio"
},
Can anyone please help me?
You have to move the $starone variable to the outside of the foreach loop so that it doesn't get overwritten inside the loop :
foreach ($queryStars->result() as $star) {
$stars[] = $star->star_name;
}
$starone = implode(", ", $stars);
Add empty array before foreach $stars=array();
$stars=array();
foreach ($queryStars->result() as $star) {
$stars[] = $star->star_name;
$starone = implode(", ", $stars);
}

Problems replacing grouped patterns with PHP regex

I have a JSON file that I want to use PHP to replace the "Systems_x0020_Changed_IDs" value from a string to an array. "39122" becomes [39122] and "39223, 39244, 39395" becomes [39223, 39244, 39395]. I am using http://www.regexpal.com/ to test my expression. The expression is:
"([(0-9)+((, *))]+)+"
This is producing unexpected results in PHP. In my JSON file:
[{
"ID": 1050436,
"Title": "THE SKY IS FALLING!!!!",
"Application_x0020_ID": 242,
"Systems_x0020_Changed": "Academic Planning System (APS),\"Documents planning and evaluation processes at UGA that support cont",
"Systems_x0020_Changed_IDs": "39122",
"Status": "New",
"Modified": "2015-10-28T16:14:45.573-04:00",
"Age": 40,
"Description_x0020__x0028_Public_x0029_": "I'm chicken little and the SKY IS FALLING!",
"Impact_x0020__x0028_Public_x0029_": "The world is going to end!",
"Start_x0020_Time": "2015-10-28T00:00:00-04:00",
"End_x0020_Time": "2015-10-30T00:00:00-04:00",
"Hours": 12
}, {
"ID": 1050740,
"Title": "This is a Title",
"Application_x0020_ID": 242,
"Systems_x0020_Changed": "EITS Websites,\"EITS departmental web pages.\", GACRC Archival Storage,\"Archival Storage for Research Data\", VPS,\"Mainframe distributed printing system\"",
"Systems_x0020_Changed_IDs": "39223, 39244, 39395",
"Status": "New",
"Modified": "2015-11-05T17:31:13.15-05:00",
"Age": 32,
"Description_x0020__x0028_Public_x0029_": "We will tell jokes to the clients",
"Impact_x0020__x0028_Public_x0029_": "Everyone will notice the change.",
"Start_x0020_Time": "2015-11-27T08:38:00-05:00",
"End_x0020_Time": "2015-11-30T00:00:00-05:00",
"Hours": 1
}]
Several commas at the end of lines are being replaced with brackets[] so that the output looks like:
[{
"ID": 1050436,
"Title": "THE SKY IS FALLING!!!![,]Application_x0020_ID": 242,
"Systems_x0020_Changed": "Academic Planning System (APS),\"Documents planning and evaluation processes at UGA that support cont[,]Systems_x0020_Changed_IDs": 39122,
"Status": "New[,]Modified": "2015-10-28T16:14:45.573-04:00[,]Age": 40,
"Description_x0020__x0028_Public_x0029_": "I'm chicken little and the SKY IS FALLING![,]Impact_x0020__x0028_Public_x0029_": "The world is going to end![,]Start_x0020_Time": "2015-10-28T00:00:00-04:00[,]End_x0020_Time": "2015-10-30T00:00:00-04:00[,]Hours": 12
}, {
"ID": 1050740,
"Title": "This is a Title[,]Application_x0020_ID": 242,
"Systems_x0020_Changed": "EITS Websites,\"EITS departmental web pages.\", GACRC Archival Storage,\"Archival Storage for Research Data\", VPS,\"Mainframe distributed printing system\"[,]Systems_x0020_Changed_IDs": [39223, 39244, 39395],
"Status": "New[,]Modified": "2015-11-05T17:31:13.15-05:00[,]Age": 32,
"Description_x0020__x0028_Public_x0029_": "We will tell jokes to the clients[,]Impact_x0020__x0028_Public_x0029_": "Everyone will notice the change.[,]Start_x0020_Time": "2015-11-27T08:38:00-05:00[,]End_x0020_Time": "2015-11-30T00:00:00-05:00[,]Hours": 1
}]
My question is, how can I modify the expression so that PHP will behave like regexpal.com and only get the numbers within quotes and ignore the rest?
Your regex is rather strange, you appear to be trying to put a pattern expression inside a character class [...], which is probably not doing what you'd expect. Furthermore, your regex would match values inside other key/value pairs. Try this instead, which will only match values for the key "Systems_x0020_Changed_IDs":
"Systems_x0020_Changed_IDs":\s+"([^"]*)"
What about just parsing it as the JSON that it is?
$jsons = array('{
"ID": 1050436,
"Title": "THE SKY IS FALLING!!!!",
"Application_x0020_ID": 242,
"Systems_x0020_Changed": "Academic Planning System (APS),\"Documents planning and evaluation processes at UGA that support cont",
"Systems_x0020_Changed_IDs": "39122",
"Status": "New",
"Modified": "2015-10-28T16:14:45.573-04:00",
"Age": 40,
"Description_x0020__x0028_Public_x0029_": "I\'m chicken little and the SKY IS FALLING!",
"Impact_x0020__x0028_Public_x0029_": "The world is going to end!",
"Start_x0020_Time": "2015-10-28T00:00:00-04:00",
"End_x0020_Time": "2015-10-30T00:00:00-04:00",
"Hours": 12
}', '{
"ID": 1050740,
"Title": "This is a Title",
"Application_x0020_ID": 242,
"Systems_x0020_Changed": "EITS Websites,\"EITS departmental web pages.\", GACRC Archival Storage,\"Archival Storage for Research Data\", VPS,\"Mainframe distributed printing system\"",
"Systems_x0020_Changed_IDs": "39223, 39244, 39395",
"Status": "New",
"Modified": "2015-11-05T17:31:13.15-05:00",
"Age": 32,
"Description_x0020__x0028_Public_x0029_": "We will tell jokes to the clients",
"Impact_x0020__x0028_Public_x0029_": "Everyone will notice the change.",
"Start_x0020_Time": "2015-11-27T08:38:00-05:00",
"End_x0020_Time": "2015-11-30T00:00:00-05:00",
"Hours": 1
}');
foreach($jsons as $json){
$json_array = json_decode($json, true);
echo $json_array['Systems_x0020_Changed_IDs'] . "\n";
}
Demo: https://eval.in/481865
If you needed a regex you could do something like:
"Systems_x0020_Changed_IDs":\h*"(([\d+],?\h*)*)"
Demo: https://regex101.com/r/yZ6eM3/1
PHP Usage:
$string = '{
"ID": 1050436,
"Title": "THE SKY IS FALLING!!!!",
"Application_x0020_ID": 242,
"Systems_x0020_Changed": "Academic Planning System (APS),\"Documents planning and evaluation processes at UGA that support cont",
"Systems_x0020_Changed_IDs": "39122",
"Status": "New",
"Modified": "2015-10-28T16:14:45.573-04:00",
"Age": 40,
"Description_x0020__x0028_Public_x0029_": "I\'m chicken little and the SKY IS FALLING!",
"Impact_x0020__x0028_Public_x0029_": "The world is going to end!",
"Start_x0020_Time": "2015-10-28T00:00:00-04:00",
"End_x0020_Time": "2015-10-30T00:00:00-04:00",
"Hours": 12
}, {
"ID": 1050740,
"Title": "This is a Title",
"Application_x0020_ID": 242,
"Systems_x0020_Changed": "EITS Websites,\"EITS departmental web pages.\", GACRC Archival Storage,\"Archival Storage for Research Data\", VPS,\"Mainframe distributed printing system\"",
"Systems_x0020_Changed_IDs": "39223, 39244, 39395",
"Status": "New",
"Modified": "2015-11-05T17:31:13.15-05:00",
"Age": 32,
"Description_x0020__x0028_Public_x0029_": "We will tell jokes to the clients",
"Impact_x0020__x0028_Public_x0029_": "Everyone will notice the change.",
"Start_x0020_Time": "2015-11-27T08:38:00-05:00",
"End_x0020_Time": "2015-11-30T00:00:00-05:00",
"Hours": 1
}';
$regex = '/"Systems_x0020_Changed_IDs":\h*"((?:[\d+],?\h*)*)"/';
preg_match_all($regex, $string, $matches);
print_r($matches[1]);
Output:
Array
(
[0] => 39122
[1] => 39223, 39244, 39395
)
Demo #2: https://eval.in/481871
The answer I was looking for is:
$str = preg_replace('/"((\d+[, ]*)+)"/', "[$1]", $str);
I needed the JSON file as is except for number values as strings. My regex worked after I played with it a little more.

json_decode returning NULL with valid JSON data

This is a snippet of code inside my JSON parser function, which is working fine with about a dozen or so various JSON files:
The prints are there for current debugging purposes
$this->response = stripslashes($this->response);
print_r($this->response);
$this->response = json_decode($this->response);
print_r($this->response);
The first print gives me the JSON string, and the second print gives me null. Using json_last_error I managed to find out that PHP was refusing to parse the JSON as it was in an invalid syntax.
This is a snipped of the JSON I'm parsing (full thing here), it validates with every validator I can find on Google:
{
"success": 1,
"stores": [
{
"name": "Winton",
"address": "370-374 , Wimborne Road, Bournemouth, Dorset BH92HE",
"telephone": "",
"email": "info#99pstoresltd.com",
"website": "",
"description": "Mon - 09.00-18.00 Tue - 09.00-18.00 Wed - 09.00-18.00 Thu - 09.00-18.00 Fri - 09.00-18.00 Sat - 09.00-18.00 Sun - 10.00-16.00",
"lat": "50.7413",
"lng": "-1.87926",
"titlewebsite": "Website",
"titleemail": "Email",
"titletel": "Telephone",
"titlecontactstore": "Contact this store",
"titlekm": "km",
"titlemiles": "miles",
"cat_name": "",
"cat_img": "",
"img": ""
},
{
"name": "Boscombe",
"address": "The Sovereign Centre, Boscombe, Bournemouth, Dorset BH14SX",
"telephone": "",
"email": "info#99pstoresltd.com",
"website": "",
"description": "Mon - 08.00-18.00 Tue - 08.00-18.00 Wed - 08.00-18.00 Thu - 08.00-18.00 Fri - 08.00-18.00 Sat - 08.00-18.00 Sun - 10.00-16.00",
"lat": "50.7272",
"lng": "-1.83952",
"titlewebsite": "Website",
"titleemail": "Email",
"titletel": "Telephone",
"titlecontactstore": "Contact this store",
"titlekm": "km",
"titlemiles": "miles",
"cat_name": "",
"cat_img": "",
"img": ""
}]
}
I have no idea why this isn't parsing as the JSON looks fine to me! Been staring at this for quite a while now so would be more than happy to here some thoughts on this.
EDIT:
Copy and pasting the data from the first print_r and pushing it through the json_decode works fine. I'm assuming this means there is an issue with where the JSON is originating from which could be messing up encoding or something?
Try this:
json_decode($this->response, true);
From the documentation about the second parameter:
When TRUE, returned objects will be converted into associative arrays.
Source: http://php.net/manual/en/function.json-decode.php

Is there a maximum length for json in Java?

I'm getting an output of the classes that students saw through all the university career.
this is an example of the output
{
"HISTORICOP": [
{
"MATERIA": "PROCESOS DEL LENGUAJE ",
"NOTA": "7 ",
"ANIO": "2000",
"PERIODO": "001",
"ENEMENOSUNO": "0 "
},
{
"MATERIA": "RAZONAMIENTO BASICO FG ",
"NOTA": "13 ",
"ANIO": "2000",
"PERIODO": "001",
"ENEMENOSUNO": "0 "
},
{
"MATERIA": "DESARROLLO DE COMPETENCIAS ",
"NOTA": "8 ",
"ANIO": "2000",
"PERIODO": "001",
"ENEMENOSUNO": "n-1 "
}
]
}
these are 3 of the results
but the whole output are 91 results,
when I run it on a emulator the blackberry is not able to read it
but when I try with less results he can read it!
Is there a maximum json length size so it can be read in java?
this is how I retrieve the info! from SAP
try {
$conn = new sapnwrfc($config);
$fds = $conn->function_lookup("ZCM_GET_HORARIO");
$parms = array('CEDULA' => '16814224');
$results = $fds->invoke($parms);
echo "[".json_encode($results)."]";
$conn->close();
} catch (Exception $e) {
echo "Connection Failed 3";
}
There is no absolute limitation in JSON. In Java there is a limit to the length of a String, which is 2^31-1 or over 2 billion characters long. But given the snippet of code you showed us you are not actually using Java (Java doesn't have "$" before variable names).
There may be a limitation in whatever library you are using which is not a fundamental limitation of the data format or the language.
But if you are having problems with just 91 items (not 91 thousand or 91 million) then it is far more likely that you problem is NOT due to a fundamental size limitation. If you post more about what actual errors you saw you might get a more useful response.

New Google Custom Search Api Results - PHP

So the new Google custom Search has rolled out and im having trouble displaying the results...
I am using php to return the results in json and am getting a invalid argument in for each error... Here is what i am using...
$url = "https://www.googleapis.com/customsearch/v1?key=MYKEY&cx=017576662512468239146:omuauf_lfve&q=test&callback=json";
$results = file_get_contents($url);
foreach ($results->items as $r)
{
}
Here's the callback when I go to the URL in the browser:
json({
"kind": "customsearch#search",
"url": {
"type": "application/json",
"template": "https://www.googleapis.com/customsearch/v1?q\u003d{searchTerms}&num\u003d{count?}&start\u003d{startIndex?}&hr\u003d{language?}&safe\u003d{safe?}&cx\u003d{cx?}&cref\u003d{cref?}&sort\u003d{sort?}&alt\u003djson"
},
"queries": {
"nextPage": [
{
"title": "Google Custom Search - test",
"totalResults": 276000000,
"searchTerms": "test",
"count": 10,
"startIndex": 11,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "017576662512468239146:omuauf_lfve"
}
],
"request": [
{
"title": "Google Custom Search - test",
"totalResults": 276000000,
"searchTerms": "test",
"count": 10,
"startIndex": 1,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "017576662512468239146:omuauf_lfve"
}
]
},
"context": {
"title": "Curriculum",
"facets": [
[
{
"label": "lectures",
"anchor": "Lectures"
}
],
[
{
"label": "assignments",
"anchor": "Assignments"
}
],
[
{
"label": "reference",
"anchor": "Reference"
}
]
]
},
"items": [
{
"kind": "customsearch#result",
"title": "Lecture 8: Pseudo Randomness and the Next-bit test 1 Review 2 ...",
"htmlTitle": "Lecture 8: Pseudo Randomness and the Next-bit \u003cb\u003etest\u003c/b\u003e 1 Review 2 \u003cb\u003e...\u003c/b\u003e",
"link": "http://www.cs.cornell.edu/courses/cs687/2008sp/scribes/scribe19Feb2008.pdf",
"displayLink": "www.cs.cornell.edu",
"snippet": "Feb 19, 2008 ... Definition 2 An ensemble {Xn} passes the Next Bit test ⇐⇒ ∀ PPT A, ... Next Bit test. We have to now prove the other direction. ...",
"htmlSnippet": "Feb 19, 2008 \u003cb\u003e...\u003c/b\u003e Definition 2 An ensemble {Xn} passes the Next Bit \u003cb\u003etest\u003c/b\u003e ⇐⇒ ∀ PPT A, \u003cb\u003e...\u003c/b\u003e Next \u003cbr\u003e Bit \u003cb\u003etest\u003c/b\u003e. We have to now prove the other direction. \u003cb\u003e...\u003c/b\u003e",
"cacheId": "ErjWs7c3umEJ",
"pagemap": {
"metatags": [
{
"producer": "MiKTeX pdfTeX-1.40.4",
"creator": "TeX",
"creationdate": "D:20080306114145-05'00'",
"moddate": "D:20080306114145-05'00'",
"fullbanner": "This is MiKTeX-pdfTeX 2.7.2808 (1.40.4)"
}
]
}
},
{
"kind": "customsearch#result",
"title": "General Information for Computer Science 227 and 228 Test-Out ...",
"htmlTitle": "General Information for Computer Science 227 and 228 \u003cb\u003eTest\u003c/b\u003e-Out \u003cb\u003e...\u003c/b\u003e",
"link": "http://www.cs.iastate.edu/gradadm/cmarquar/testout.pdf",
"displayLink": "www.cs.iastate.edu",
"snippet": "should fill out an application for a test-out in the main office and find ... \" Students may ordinarily attempt a CBE test only once in any course or area. ...",
"htmlSnippet": "should fill out an application for a \u003cb\u003etest\u003c/b\u003e-out in the main office and find \u003cb\u003e...\u003c/b\u003e "\u003cbr\u003e Students may ordinarily attempt a CBE \u003cb\u003etest\u003c/b\u003e only once in any course or area. \u003cb\u003e...\u003c/b\u003e",
"cacheId": "HvE3JGhnVkgJ",
"pagemap": {
"metatags": [
{
"creationdate": "D:20091006145719-05'00'",
"author": "prabhu",
"creator": "PScript5.dll Version 5.2.2",
"producer": "Acrobat Distiller 7.0 (Windows)",
"moddate": "D:20091006145719-05'00'"
}
]
}
},
{
"kind": "customsearch#result",
"title": "CS1130 Grades/exams/assignments",
"htmlTitle": "CS1130 Grades/exams/assignments",
"link": "http://www.cs.cornell.edu/courses/cs1130/2010fa/gradesexams.html",
"displayLink": "www.cs.cornell.edu",
"snippet": "There will be two tests. The exams require mastery of the material: you will be expected to get 85% on each test. If you get lower than 85% on a test, ...",
"htmlSnippet": "There will be two \u003cb\u003etests\u003c/b\u003e. The exams require mastery of the material: you will be \u003cbr\u003e expected to get 85% on each \u003cb\u003etest\u003c/b\u003e. If you get lower than 85% on a \u003cb\u003etest\u003c/b\u003e, \u003cb\u003e...\u003c/b\u003e",
"cacheId": "fjSAJnTr0FgJ"
},
{
"kind": "customsearch#result",
"title": "Lecture 16: Recognition II Outline Model-based recognition ...",
"htmlTitle": "Lecture 16: Recognition II Outline Model-based recognition \u003cb\u003e...\u003c/b\u003e",
"link": "http://www.cs.utexas.edu/~grauman/courses/378/slides/lecture16.pdf",
"displayLink": "www.cs.utexas.edu",
"snippet": "Hypothesize and test. • Given model of object .... Hypothesize and test: looking for object and ... “Test” as function of these representations that ...",
"htmlSnippet": "Hypothesize and \u003cb\u003etest\u003c/b\u003e. • Given model of object \u003cb\u003e....\u003c/b\u003e Hypothesize and \u003cb\u003etest\u003c/b\u003e: looking \u003cbr\u003e for object and \u003cb\u003e...\u003c/b\u003e “\u003cb\u003eTest\u003c/b\u003e” as function of these representations that \u003cb\u003e...\u003c/b\u003e",
"cacheId": "_QUgy1DsMFgJ",
"pagemap": {
"metatags": [
{
"creationdate": "D:20071108175221-06'00'",
"author": "grauman",
"creator": "PScript5.dll Version 5.2.2",
"producer": "Acrobat Distiller 8.1.0 (Windows)",
"moddate": "D:20071108175221-06'00'"
}
]
}
},
{
"kind": "customsearch#result",
"title": "Notes on the Miller-Rabin randomized primality test",
"htmlTitle": "Notes on the Miller-Rabin randomized primality \u003cb\u003etest\u003c/b\u003e",
"link": "http://www.cs.cornell.edu/courses/cs482/2008sp/handouts/mrpt.pdf",
"displayLink": "www.cs.cornell.edu",
"snippet": "Apr 25, 2008 ... test whether a number is prime. It is called the Miller-Rabin primality .... The Miller-Rabin test is based on a third way to prove that a ...",
"htmlSnippet": "Apr 25, 2008 \u003cb\u003e...\u003c/b\u003e \u003cb\u003etest\u003c/b\u003e whether a number is prime. It is called the Miller-Rabin primality \u003cb\u003e....\u003c/b\u003e The \u003cbr\u003e Miller-Rabin \u003cb\u003etest\u003c/b\u003e is based on a third way to prove that a \u003cb\u003e...\u003c/b\u003e",
"cacheId": "IP9TrtclTpAJ",
"pagemap": {
"metatags": [
{
"producer": "pdfTeX-1.40.3",
"creator": "TeX",
"creationdate": "D:20080424173852-04'00'",
"moddate": "D:20080424173852-04'00'",
"fullbanner": "This is pdfTeX, Version 3.141592-1.40.3-2.2 (Web2C 7.5.6) kpathsea version 3.5.6"
}
]
}
},
{
"kind": "customsearch#result",
"title": "TOWARD A THEORY OF TEST DATA SELECTION John B. Go0denough Susan L ...",
"htmlTitle": "TOWARD A THEORY OF \u003cb\u003eTEST\u003c/b\u003e DATA SELECTION John B. Go0denough Susan L \u003cb\u003e...\u003c/b\u003e",
"link": "http://www.cs.umd.edu/class/spring2003/cmsc838p/VandV/criteria.pdf",
"displayLink": "www.cs.umd.edu",
"snippet": "Formal Definitions and the Fundamental Theorem of Testing criterion is reliable if and only if ... set of test data, i. e. , if it can be shown that for ...",
"htmlSnippet": "Formal Definitions and the Fundamental Theorem of \u003cb\u003eTesting\u003c/b\u003e criterion is reliable \u003cbr\u003e if and only if \u003cb\u003e...\u003c/b\u003e set of \u003cb\u003etest\u003c/b\u003e data, i. e. , if it can be shown that for \u003cb\u003e...\u003c/b\u003e",
"cacheId": "44B1_Z8kNHYJ",
"pagemap": {
"metatags": [
{
"moddate": "D:20010115130600-05'00'",
"creationdate": "D:20010114103427-05'00'"
}
]
}
},
{
"kind": "customsearch#result",
"title": "Lecture Notes 16 - pmwiki - Main.homepage",
"htmlTitle": "Lecture Notes 16 - pmwiki - Main.homepage",
"link": "http://zoo.cs.yale.edu/classes/cs467/2008f/attach/ln16.html",
"displayLink": "zoo.cs.yale.edu",
"snippet": "Nov 3, 2008 ... If n is prime, the test always fails by Theorem 1 of section 68. ... The test μa (n) is based on computing a sequence b0,b1,…,bs of integers ...",
"htmlSnippet": "Nov 3, 2008 \u003cb\u003e...\u003c/b\u003e If n is prime, the \u003cb\u003etest\u003c/b\u003e always fails by Theorem 1 of section 68. \u003cb\u003e...\u003c/b\u003e The \u003cb\u003etest\u003c/b\u003e μa\u003cbr\u003e (n) is based on computing a sequence b0,b1,…,bs of integers \u003cb\u003e...\u003c/b\u003e",
"cacheId": "TnMAQxlY3HIJ",
"pagemap": {
"metatags": [
{
"originator": "TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)",
"src": "ln16.tex",
"date": "2008-11-11 16:55:00"
}
]
}
},
{
"kind": "customsearch#result",
"title": "CS 337 Test 3 5/5/06 Open book and notes. Max points \u003d 50 Time ...",
"htmlTitle": "CS 337 \u003cb\u003eTest\u003c/b\u003e 3 5/5/06 Open book and notes. Max points \u003d 50 Time \u003cb\u003e...\u003c/b\u003e",
"link": "http://www.cs.utexas.edu/users/misra/Classes.dir/337quizSoln.dir/S06.quiz3.pdf",
"displayLink": "www.cs.utexas.edu",
"snippet": "Test 3. 5/5/06. Open book and notes. Max points \u003d 50. Time \u003d 50 min. Do all questions. 1. (Relational Algebra; 15 points) ...",
"htmlSnippet": "\u003cb\u003eTest\u003c/b\u003e 3. 5/5/06. Open book and notes. Max points \u003d 50. Time \u003d 50 min. Do all \u003cbr\u003e questions. 1. (Relational Algebra; 15 points) \u003cb\u003e...\u003c/b\u003e",
"cacheId": "ClTLaytSRUIJ",
"pagemap": {
"metatags": [
{
"creator": "TeX output 2006.05.04:1646",
"producer": "dvipdfm 0.13.2c, Copyright Š 1998, by Mark A. Wicks",
"creationdate": "D:20060504164645-06'00'"
}
]
}
},
{
"kind": "customsearch#result",
"title": "EE410 Test Structures & Testing",
"htmlTitle": "EE410 \u003cb\u003eTest\u003c/b\u003e Structures & \u003cb\u003eTesting\u003c/b\u003e",
"link": "http://www.stanford.edu/class/ee410/TestStructures.pdf",
"displayLink": "www.stanford.edu",
"snippet": "Test every unique structure at least once, but don't waste time testing ..... Take good care of the testing setup — it's your only one and it cannot ...",
"htmlSnippet": "\u003cb\u003eTest\u003c/b\u003e every unique structure at least once, but don't waste time \u003cb\u003etesting\u003c/b\u003e \u003cb\u003e.....\u003c/b\u003e \u003cbr\u003e Take good care of the \u003cb\u003etesting\u003c/b\u003e setup — it's your only one and it cannot \u003cb\u003e...\u003c/b\u003e",
"cacheId": "YKadfqMlYuIJ",
"pagemap": {
"metatags": [
{
"author": "Krishna Saraswat",
"producer": "Mac OS X 10.6.6 Quartz PDFContext",
"creator": "Microsoft PowerPoint",
"creationdate": "D:20110209003235Z00'00'",
"moddate": "D:20110209003235Z00'00'"
}
]
}
},
{
"kind": "customsearch#result",
"title": "SIP: Interoperability Test Event FAQ",
"htmlTitle": "SIP: Interoperability \u003cb\u003eTest\u003c/b\u003e Event FAQ",
"link": "http://www.cs.columbia.edu/sip/sipit/faq.html",
"displayLink": "www.cs.columbia.edu",
"snippet": "\"The interoperability test event is for non-competitve, friendly testing of ... It is meant as someplace people can come to, and test their code at, ...",
"htmlSnippet": ""The interoperability \u003cb\u003etest\u003c/b\u003e event is for non-competitve, friendly \u003cb\u003etesting\u003c/b\u003e of \u003cb\u003e...\u003c/b\u003e \u003cbr\u003e It is meant as someplace people can come to, and \u003cb\u003etest\u003c/b\u003e their code at, \u003cb\u003e...\u003c/b\u003e",
"cacheId": "m7jgghXfi78J",
"pagemap": {
"metatags": [
{
"author": "Henning Schulzrinne"
}
]
}
}
]
}
);
You should try this:
$results = json_decode(file_get_contents($url));
To be able to correctly decode the response of the service, you may do the following:
$json = file_get_contents($url);
$start = 'json(';
$end = ');';
$substr_start_pos = strpos($json, $start) + strlen($start);
$substr_length = strlen($json) - $substr_start_pos - (strlen($json) - strrpos($json, $end));
$json = substr($json, $substr_start_pos, $substr_length);
$results = json_decode($json);
This may be a bit confusing, but I did this for the following reasons:
The sample response you provided, has a 'json(' string before the actual JSON, and a ');' after it, which can't be decoded with PHP's json_decode.
Simple replacing won't be good, because the actual JSON might contain these substrings as well.
THIS IS TRUE SIMPLE PHP DECODE WILL NOT HELP YOU,
TRY THIS
$data = html_entity_decode($url);
I am sure this will work properly
to try later var dump the date to check the results.

Categories