source: branches/0.4/web/addons/job_monarch/dwoo/plugins/builtin/functions/capitalize.php @ 755

Last change on this file since 755 was 755, checked in by ramonb, 11 years ago
  • add Dwoo
File size: 1.1 KB
Line 
1<?php
2
3/**
4 * Capitalizes the first letter of each word
5 * <pre>
6 *  * value : the string to capitalize
7 *  * numwords : if true, the words containing numbers are capitalized as well
8 * </pre>
9 * This software is provided 'as-is', without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from the use of this software.
11 *
12 * @author     Jordi Boggiano <j.boggiano@seld.be>
13 * @copyright  Copyright (c) 2008, Jordi Boggiano
14 * @license    http://dwoo.org/LICENSE   Modified BSD License
15 * @link       http://dwoo.org/
16 * @version    1.1.0
17 * @date       2009-07-18
18 * @package    Dwoo
19 */
20function Dwoo_Plugin_capitalize(Dwoo_Core $dwoo, $value, $numwords=false)
21{
22        if ($numwords || preg_match('#^[^0-9]+$#',$value))
23        {
24                return mb_convert_case((string) $value,MB_CASE_TITLE, $dwoo->getCharset());
25        } else {
26                $bits = explode(' ', (string) $value);
27                $out = '';
28                while (list(,$v) = each($bits)) {
29                        if (preg_match('#^[^0-9]+$#', $v)) {
30                                $out .= ' '.mb_convert_case($v, MB_CASE_TITLE, $dwoo->getCharset());
31                        } else {
32                                $out .= ' '.$v;
33                        }
34                }
35
36                return substr($out, 1);
37        }
38}
Note: See TracBrowser for help on using the repository browser.