PHP code example of fofx / utility

1. Go to this page and download the library: Download fofx/utility library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fofx / utility example snippets




use FOfX\Utility;
use Illuminate\Support\Arr;

$filename = __DIR__ . '/../resources/2-httpswwwfiverrcomcategoriesgraphics-designcreative-logo-design-fiverrcom-browserhtml.html';
$html = file_get_contents($filename);
$blocks = Utility\extract_embedded_json_blocks($html);
$filtered = Utility\filter_json_blocks_by_selector($blocks, 'perseus-initial-props', true);
// Use Arr::dot() to get a dot notation list of keys, to see the JSON structure
$dot_keys_only = array_keys(Arr::dot($filtered[0] ?? []));
print_r($dot_keys_only);

use FOfX\Utility\FiverrSitemapImporter;

$importer = new FiverrSitemapImporter();
$importer->setBatchSize(500); // optional (default 100)

// Categories
$stats = $importer->importCategories();
print_r($stats);

// Tags
$stats = $importer->importTags();
print_r($stats);

use FOfX\Utility;

$filename = __DIR__ . '/../resources/2-httpswwwfiverrcomcategoriesgraphics-designcreative-logo-design-fiverrcom-browserhtml.html';
$html     = file_get_contents($filename);
$blocks   = Utility\extract_embedded_json_blocks($html);
$filtered = Utility\filter_json_blocks_by_selector($blocks, 'perseus-initial-props', true);
// Infer Laravel database columns types from the filtered JSON
// At the first item, first listing, first gig
$types   = Utility\inspect_json_types($filtered[0]['listings'][0]['gigs'][0], delimiter: '__', infer: true);
$columns = Utility\types_to_columns($types);
print_r($columns);