Created
November 29, 2022 00:16
-
-
Save uzielweb/06f2f82101f831eb8d067dedfc4e6094 to your computer and use it in GitHub Desktop.
php fontawesome for Joomla
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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