@ 2023-05-26T14:08:22Z <?php
function svg_icon(array $atts = []): ?string
{
// Get the provided values or a default value
$icon = $atts['icon'] ?? false;
$label = $atts['label'] ?? false;
// This is required, so if it not set bail
if (!$icon) {
return null;
}
// These are our possible SVGs
static $config = [
'arrow' => '<svg aria-hidden="true" role="img" focusable="false" width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd"><path d="M21.883 12l-7.527 6.235.644.765 9-7.521-9-7.479-.645.764 7.529 6.236h-21.884v1h21.883z"/></svg>',
'hamburger' => '<svg aria-hidden="true" role="img" focusable="false" clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="m13 16.745c0-.414-.336-.75-.75-.75h-9.5c-.414 0-.75.336-.75.75s.336.75.75.75h9.5c.414 0 .75-.336.75-.75zm9-5c0-.414-.336-.75-.75-.75h-18.5c-.414 0-.75.336-.75.75s.336.75.75.75h18.5c.414 0 .75-.336.75-.75zm-4-5c0-.414-.336-.75-.75-.75h-14.5c-.414 0-.75.336-.75.75s.336.75.75.75h14.5c.414 0 .75-.336.75-.75z" fill-rule="nonzero"/></svg>',
'close' => '<svg aria-hidden="true" role="img" focusable="false" clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="m12.002 2.005c5.518 0 9.998 4.48 9.998 9.997 0 5.518-4.48 9.998-9.998 9.998-5.517 0-9.997-4.48-9.997-9.998 0-5.517 4.48-9.997 9.997-9.997zm0 1.5c-4.69 0-8.497 3.807-8.497 8.497s3.807 8.498 8.497 8.498 8.498-3.808 8.498-8.498-3.808-8.497-8.498-8.497zm0 7.425 2.717-2.718c.146-.146.339-.219.531-.219.404 0 .75.325.75.75 0 .193-.073.384-.219.531l-2.717 2.717 2.727 2.728c.147.147.22.339.22.531 0 .427-.349.75-.75.75-.192 0-.384-.073-.53-.219l-2.729-2.728-2.728 2.728c-.146.146-.338.219-.53.219-.401 0-.751-.323-.751-.75 0-.192.073-.384.22-.531l2.728-2.728-2.722-2.722c-.146-.147-.219-.338-.219-.531 0-.425.346-.749.75-.749.192 0 .385.073.531.219z" fill-rule="nonzero"/></svg>',
];
// If the requested icon doesn't exist, bail
if (!$svg = $config[$icon] ?? null) {
return null;
}
// If we have a label, un-hide the SVG and set the ARIA attribute
if (!empty($label)) {
$svg = str_replace('<svg ', '<svg aria-label="'.esc_attr($label).'"', $svg);
$svg = str_replace('aria-hidden="true"', '', $svg);
}
return $svg;
}
// Samples
echo svg_icon(['icon' => 'hamburger', 'label' => 'Main Menu']);
echo PHP_EOL;
echo svg_icon(['icon' => 'arrow', 'label' => 'Click me']);
echo PHP_EOL;
echo svg_icon(['icon' => 'close']);
echo PHP_EOL;
echo svg_icon(['icon' => 'nope']);
echo PHP_EOL;
// !! DO NOT COPY THIS FUNCTION !!
// This is a stub-function ONLY for the 3v4l.org site.
function esc_attr($string){return $string;}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.4.12 0.009 0.009 24.17 8.4.11 0.011 0.010 21.44 8.4.10 0.005 0.006 18.98 8.4.9 0.011 0.009 18.71 8.4.8 0.004 0.005 17.71 8.4.7 0.011 0.008 17.89 8.4.6 0.013 0.009 20.48 8.4.5 0.011 0.009 17.75 8.4.4 0.003 0.013 20.46 8.4.3 0.013 0.006 22.23 8.4.2 0.008 0.000 19.59 8.4.1 0.000 0.008 22.05 8.3.25 0.009 0.009 18.91 8.3.24 0.006 0.003 17.16 8.3.23 0.012 0.006 16.61 8.3.22 0.011 0.007 17.22 8.3.21 0.010 0.007 21.16 8.3.20 0.003 0.006 16.55 8.3.19 0.015 0.005 16.46 8.3.18 0.013 0.006 16.58 8.3.17 0.004 0.011 18.97 8.3.16 0.009 0.009 16.69 8.3.15 0.006 0.009 20.95 8.3.14 0.000 0.008 16.54 8.3.13 0.004 0.004 18.61 8.3.12 0.003 0.007 19.07 8.3.11 0.000 0.009 20.94 8.3.10 0.003 0.006 24.06 8.3.9 0.003 0.006 26.77 8.3.8 0.003 0.006 16.63 8.3.7 0.009 0.006 18.31 8.3.6 0.006 0.009 16.88 8.3.5 0.016 0.006 16.89 8.3.4 0.007 0.007 20.29 8.3.3 0.006 0.009 18.81 8.3.2 0.007 0.000 24.18 8.3.1 0.004 0.004 24.66 8.3.0 0.008 0.000 26.16 8.2.29 0.010 0.008 20.68 8.2.28 0.006 0.006 20.08 8.2.27 0.012 0.006 17.41 8.2.26 0.005 0.003 20.70 8.2.25 0.007 0.003 18.47 8.2.24 0.004 0.004 18.92 8.2.23 0.013 0.009 22.58 8.2.22 0.006 0.003 37.54 8.2.21 0.008 0.000 26.77 8.2.20 0.007 0.004 16.63 8.2.19 0.011 0.004 18.16 8.2.18 0.014 0.007 16.75 8.2.17 0.011 0.004 19.08 8.2.16 0.009 0.006 22.96 8.2.15 0.000 0.008 25.66 8.2.14 0.008 0.000 24.66 8.2.13 0.007 0.000 26.16 8.2.12 0.004 0.004 21.18 8.2.11 0.011 0.000 20.52 8.2.10 0.000 0.009 20.39 8.2.6 0.010 0.005 17.44 8.1.33 0.016 0.007 21.91 8.1.32 0.011 0.008 16.27 8.1.31 0.016 0.003 16.81 8.1.30 0.005 0.003 16.07 8.1.29 0.006 0.012 30.84 8.1.28 0.016 0.006 25.92 8.1.27 0.007 0.007 24.66 8.1.26 0.003 0.006 26.35 8.1.25 0.004 0.004 28.09 8.1.24 0.006 0.003 20.70 8.1.23 0.006 0.003 18.49
preferences:dark mode live preview ace vim emacs key bindings
28.57 ms | 403 KiB | 5 Q