You are here

public static function Typogrify::amp in Typogrify 7

Same name and namespace in other branches
  1. 5 typogrify.class.php \Typogrify::amp()
  2. 6 typogrify.class.php \Typogrify::amp()

Enable custom styling of ampersands.

Wraps apersands in html with '<span class="amp">', so they can be styled with CSS. Ampersands are also normalized to '&amp;. Requires ampersands to have whitespace or an '&nbsp;' on both sides.

It won't mess up & that are already wrapped, in entities or URLs

Parameters

string:

Return value

string

3 calls to Typogrify::amp()
SmartAmpersand in ./smartypants.php
Wrapping ampersands.
Typogrify::filter in ./typogrify.class.php
typogrify
TypogrifyClassTestCase::testAmpersandWrapping in tests/typogrify.class.test
Tests ampersand-wrapping.

File

./typogrify.class.php, line 19
typogrify.class.php Defines a class for providing different typographical tweaks to HTML

Class

Typogrify
@file typogrify.class.php Defines a class for providing different typographical tweaks to HTML

Code

public static function amp($text) {
  $amp_finder = "/(\\s|&nbsp;)(&|&amp;|&\\#38;|&#038;)(\\s|&nbsp;)/";
  return preg_replace($amp_finder, '\\1<span class="amp">&amp;</span>\\3', $text);
}