Skip to content

Instantly share code, notes, and snippets.

@Yalme
Created August 3, 2022 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yalme/22209582bb1eaa80e920f953c4a9fb89 to your computer and use it in GitHub Desktop.
Save Yalme/22209582bb1eaa80e920f953c4a9fb89 to your computer and use it in GitHub Desktop.
Get SVG through PHP with cache
function get_svg($path = '')
{
// yal_debug($path);
if (empty($path)) return '';
static $cache = array();
$svg = '';
$key = md5($path);
if (!empty($cache[$key])) {
$svg = $cache[$key];
} else {
if (file_exists($path)) {
$svg = file_get_contents($path);
$cache[$key] = $svg;
}
}
return $svg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment