Folks,
I just signed-up here.
I am a beginner and still on Procedural Style Php.
Do you mind converting this code to Procedural Style so I can learn from it to extract jSon off from a cURL fetched webpage ?
You see, I do not understand this oop style.
<?php
//Code from: https://potentpages.com/web-crawler-development/tutorials/php/techniques
//Assuming your contents are in a vairable called $contents
//Check if the JSON is valid
//Attempt to decode; return true for valid if no errors were found.
//Otherwise return false for an error
function checkIfJSONValid($t) {
json_decode($t);
if(json_last_error() == JSON_ERROR_NONE) {
return true;
}
return false;
}
//Match all JSON and filter for valid JSON contents
$json_matches = Array();
$pattern = '/\{(?:[^{}|(?R))*\}/x';
preg_match_all($pattern, $contents, $json_matches);
$json_valid = array_filter($json_matches, 'checkIfJSONValid');
//Loop through all valid JSON strings
foreach( $json_valid as $json ) {
//Decode JSON
//Second parameter specifies to use an associative array for the decoded JSON data
$data = json_decode($t, true);
//JSON is now in an array in the $data variable
}
?>