Skip to content

Instantly share code, notes, and snippets.

@uzielweb
Created November 29, 2022 00:16
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 uzielweb/06f2f82101f831eb8d067dedfc4e6094 to your computer and use it in GitHub Desktop.
Save uzielweb/06f2f82101f831eb8d067dedfc4e6094 to your computer and use it in GitHub Desktop.
php fontawesome for Joomla
<?php
// change $content with your html content
// replace any <i class fa fa-xxx> with svg equivalent
// fa-b, fa-brands, fa-light, fa-regular, fa-solid, fa-duotone, fas, far, fal, fab, fad
preg_match_all('@<' . 'i class="fa-(.*) fa-(.*)"' . '>@Us', $content, $newmatches);
$svgMatchs = $newmatches[2];
foreach ($svgMatchs as $key=>$svgMatch) {
$svgFile = JPATH_BASE.$tpath . '/svgs/' . $newmatches[1][$key] . '/' . $svgMatch . '.svg';
if (file_exists($svgFile)) {
$svg = file_get_contents($svgFile);
$content = str_replace('<i class="fa-' . $newmatches[1][$key] . ' fa-' . $svgMatch . '"></i>', $svg, $content);
}
}
echo $content;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment