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)); + } +}