PHP code example of granam / assets-version

1. Go to this page and download the library: Download granam/assets-version 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/ */

    

granam / assets-version example snippets


$assetsVersionInjector = new \Granam\AssetsVersion\AssetsVersionInjector();
$contentWithVersions = $assetsVersionInjector->addVersionsToAssetLinks(
<<<HTML
<link href="/assets/css/bootstrap-v3.4.1.css" rel="stylesheet" type="text/css"/><!--this will be ignored due to a excluding regexp-->
<link href="/assets/css/style.css" rel="stylesheet" type="text/css"/>
<link href="/assets/css/perex.css" rel="stylesheet" type="text/css"/>
HTML
    , '~\d+[.]\d+[.]\d+~', // exclude links with version-like names
    __DIR__ . '/web'
);
/*
<link href="/assets/css/bootstrap-v3.4.1.css" rel="stylesheet" type="text/css"/><!--this will be ignored due to a excluding regexp-->
<link href="/assets/css/style.css?version=f395e65bcd4671fc77ce01c521c9e29a" rel="stylesheet" type="text/css"/>
<link href="/assets/css/perex.css?version=7ace2a8e3e0501c9539760a0e08d9378" rel="stylesheet" type="text/css"/>
*/