Initial commit.
This commit is contained in:
35
lib/php/monica/captitle.inc.php
Normal file
35
lib/php/monica/captitle.inc.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// File name: captitle.inc.php
|
||||
// Description: PHP subroutines to capitalize a title
|
||||
// Date: 2006-08-30
|
||||
// Author: imacat <imacat@pristine.com.tw>
|
||||
// Copyright: Copyright (C) 2006-2007 Pristine Communications
|
||||
|
||||
// capitalize_title: Capitalize a title
|
||||
function capitalize_title($title)
|
||||
{
|
||||
$title = preg_replace("/\\b(\\w+)\\b/ie", "_captitle_capitalize_word(\"\\1\");", strtolower($title));
|
||||
$title = preg_replace("/(: +)(\\w+)\\b/ie", "\"\\1\" . ucfirst(\"\\2\");", $title);
|
||||
$title = preg_replace("/'S /", "'s ", $title);
|
||||
return ucfirst($title);
|
||||
}
|
||||
|
||||
// _captitle_capitalize_word: Capitalize a word
|
||||
function _captitle_capitalize_word($word)
|
||||
{
|
||||
// Words that should not be capitalized
|
||||
if (preg_match("/^(a|about|across|after|against|along|among|an|and|around|at|before|below|beneath|beside|besides|between|beyond|but|but|by|concerning|despite|down|during|except|excepting|for|for|from|in|into|like|near|nor|of|off|on|or|past|regarding|since|so|the|through|throughout|thus|till|to|toward|under|underneath|up|upon|with|within|without|yet)$/i", $word)) {
|
||||
return strtolower($word);
|
||||
}
|
||||
// Words without any vowel that look like an abbreviation
|
||||
if (!preg_match("/[aeiou]/i", $word)) {
|
||||
return strtoupper($word);
|
||||
}
|
||||
// Words that look like a roman number
|
||||
if (preg_match("/^(?:i|ii|iii|iv|v|vi|vii|viii|ix|x|xi|xii|xiii)$/i", $word)) {
|
||||
return strtoupper($word);
|
||||
}
|
||||
return ucfirst($word);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user