protected static function SmartyPants::numberReplacer in Typogrify 8
Internal: wraps and inserts space in numbers.
Parameters
array $hit: A matcher-array from preg_replace_callback.
string $thbl: The kind of whitespace to add.
Return value
string The first non-empty numeric string in $hit. Depending on where in the array it is, add the $thbl whitespace and wrap in a <span>.
4 calls to SmartyPants::numberReplacer()
- SmartyPants::numberJustSpan in src/
SmartyPants.php - Wrapping numbers and adding whitespace by setting margin-left in a span.
- SmartyPants::numberNarrownbsp in src/
SmartyPants.php - Wrapping numbers and adding whitespace '&narrownbsp;'.
- SmartyPants::numberSpan in src/
SmartyPants.php - Wrapping numbers and adding whitespace by setting margin-left in a span.
- SmartyPants::numberThinsp in src/
SmartyPants.php - Wrapping numbers and adding whitespace ' '.
File
- src/
SmartyPants.php, line 704
Class
- SmartyPants
- SmartyPants - Smart punctuation for web sites.
Namespace
Drupal\typogrifyCode
protected static function numberReplacer(array $hit, $thbl) {
if ($hit[1] != '') {
// Html-entity number: don't touch.
return $hit[1];
}
elseif ($hit[2] != '') {
// Html-entity number: don't touch.
return $hit[2];
}
elseif ($hit[3] != '') {
// Don't format german phone-numbers.
return $hit[3];
}
elseif ($hit[4] != '') {
// Date -`iso don't touch.
return $hit[4];
}
elseif ($hit[5] != '') {
// Date -`dd.mm.yyyy don't touch.
return $hit[5];
}
if (preg_match('/[+-]?\\d{5,}/', $hit[6]) == 1) {
$dec = preg_replace('/[+-]?\\d{1,3}(?=(\\d{3})+(?!\\d))/', '\\0' . $thbl, $hit[6]);
}
else {
$dec = $hit[6];
}
$frac = preg_replace('/\\d{3}/', '\\0' . $thbl, $hit[7]);
return '<span class="number">' . $dec . $frac . '</span>';
}