note 117918 added to function.ucwords

From: Date: Tue, 01 Sep 2015 14:36:33 +0000
Subject: note 117918 added to function.ucwords
Groups: php.notes 
Request: Send a blank email to php-notes+get-203554@lists.php.net to get a copy of this message
This will correct capitalisation in names taking note of special capitalisation for Mc..., Mac..., and O'... Other special cases, of which I am not aware, can be added easily. This is just a slight improvement on "deepdene at email dot com"'s name_case function... Thank you for original function. <?php function name_case($name) { if( !$name ) return $name; $newname = strtoupper($name[0]); $break = false; for( $i=1; $i<strlen($name); ++$i ) { $subed = substr($name, $i, 1); if( ord($subed) > 64 && ord($subed) < 123 || ord($subed) > 48 && ord($subed) < 58 ) { if( $break ) { $newname .= strtoupper($subed); } elseif( $i > 1 && in_array(substr($newname, $i-2, 2), array('Mc', 'O\'')) || $i > 2 && in_array(substr($newname, $i-3, 3), array('Mac')) ) { $newname .= strtoupper($subed); } else { $newname .= strtolower($subed); } $break = false; } else { // not a letter - a boundary $newname .= $subed; $break = true; } } return $newname; ?> ---- Server IP: 72.52.91.14 Probable Submitter: 146.198.149.170 ---- Manual Page -- http://php.net/manual/en/function.ucwords.php Edit -- https://master.php.net/note/edit/117918 Del: integrated -- https://master.php.net/note/delete/117918/integrated Del: useless -- https://master.php.net/note/delete/117918/useless Del: bad code -- https://master.php.net/note/delete/117918/bad+code Del: spam -- https://master.php.net/note/delete/117918/spam Del: non-english -- https://master.php.net/note/delete/117918/non-english Del: in docs -- https://master.php.net/note/delete/117918/in+docs Del: other reasons-- https://master.php.net/note/delete/117918 Reject -- https://master.php.net/note/reject/117918 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203554) next »