PHP code example of jpruliere / random-content-generator

1. Go to this page and download the library: Download jpruliere/random-content-generator 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/ */

    

jpruliere / random-content-generator example snippets


// create a new generator with this simple line
$gen = new RandomContentGenerator(['id' => 'i:0-10000', 'title' => 't:3-10w', 'illustration' => 'p:1500*900'], 30);
// here we asked for a collection of 30 arrays, each having an 'id', a 'title' and an 'illustration'
// you can ask for 4 different types of data, each with their own options, using the syntax 'type:options'
// integer [type i], the only option is a range to limit possible values (here between 0 and 10k), you can omit it, it will default to 0 - mt_getrandmax()
// float [type f], same option, the range, defaults to 0 - 1
// text [type t], you have to provide a length as option, either fixed or varying (with the dash), either in words (w) or in sentences (s)
// picture [type p], you have to provide width and height with an asterisk as separator

// get your data
$gen->fetchAll(); // all at once
// $gen->fetch(); // or line by line

// or get model instances directly
$gen->fetchAllObj(ArtworkModel::class); // all at once
// $gen->fetchObj(ArtworkModel::class); // or one by one