From 2d43e94b72b5bd40a6396176bd2baf4c14fb0ca9 Mon Sep 17 00:00:00 2001 From: Nate Nolting Date: Tue, 23 Oct 2018 13:23:05 -0500 Subject: [PATCH] Added superscript HTML helper Wrap special characters that should be super scripted with the tag. --- src/Bandolier/Type/Html/SpecialCharacter.php | 40 ++++++++++++++++++++ tests/Type/Html/SpecialCharacterTest.php | 26 +++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/Bandolier/Type/Html/SpecialCharacter.php create mode 100644 tests/Type/Html/SpecialCharacterTest.php diff --git a/src/Bandolier/Type/Html/SpecialCharacter.php b/src/Bandolier/Type/Html/SpecialCharacter.php new file mode 100644 index 0000000..79b7aa4 --- /dev/null +++ b/src/Bandolier/Type/Html/SpecialCharacter.php @@ -0,0 +1,40 @@ + ['®', '®', '®', '®'], + 'trademark' => ['™', '™', '™'], + 'copyright' => ['©', '©', '©'], + 'service' => ['℠', '℠'], + 'phonogram' => ['℗', '℗'], + 'hechsher' => ['Ⓤ', 'Ⓤ'] + ]; + $characters = array_merge($defaults, $characters); + $specials = array(); + array_walk_recursive($characters, function ($v) use (&$specials) { + $specials[] = $v; + }); + // wrap all the special characters above with superscript tags + for ($i = 0, $iCount = count($specials); $i < $iCount; $i++) { + if (strpos($string, $specials[0]) !== false) { + $string = str_replace($specials[$i], '' . $specials[$i] . '', $string); + } + } + + return $string; + } +} \ No newline at end of file diff --git a/tests/Type/Html/SpecialCharacterTest.php b/tests/Type/Html/SpecialCharacterTest.php new file mode 100644 index 0000000..62eeabc --- /dev/null +++ b/tests/Type/Html/SpecialCharacterTest.php @@ -0,0 +1,26 @@ + + * @package Pbc\Bandolier\Type\Html + * @subpackage Subpackage + */ + +namespace Pbc\Bandolier\Type\Html; + + +class SpecialCharacterTest extends \PHPUnit_Framework_TestCase +{ + + public function testSuperscriptSpecialCharacters() + { + $string = "This® Thing™ is©"; + $stringAfter = "This® Thing is©"; + + $this->assertSame($stringAfter, SpecialCharacter::superscriptSpecialCharacters($string)); + } +}