note 73216 added to function.ucwords

From: Date: Tue, 13 Feb 2007 17:16:21 +0000
Subject: note 73216 added to function.ucwords
Groups: php.notes 
Request: Send a blank email to php-notes+get-123327@lists.php.net to get a copy of this message
To get some sort of title case with lower-case articles, prepositions etc., try something like this (removing the carriage returns in the regular expression): <?php function lower_articles($str) { return preg_replace( "/(?<=(?<!:|’s)\W) (A|An|And|At|For|In|Of|On|Or|The|To|With) (?=\W)/e", 'strtolower("$1")', $str ); } ?> I added the lookbehind (?<!:|’s) because I use this for film titles, where words following those terms should be capitalised (e.g. Lemony Snicket’s A Series of Unfortunate Events, American Pie Presents: The Naked Mile). ---- Server IP: 83.138.144.80 Probable Submitter: 80.47.234.107 ---- Manual Page -- http://www.php.net/manual/en/function.ucwords.php Edit -- https://master.php.net/note/edit/73216 Del: integrated -- https://master.php.net/note/delete/73216/integrated Del: useless -- https://master.php.net/note/delete/73216/useless Del: bad code -- https://master.php.net/note/delete/73216/bad+code Del: spam -- https://master.php.net/note/delete/73216/spam Del: non-english -- https://master.php.net/note/delete/73216/non-english Del: in docs -- https://master.php.net/note/delete/73216/in+docs Del: other reasons-- https://master.php.net/note/delete/73216 Reject -- https://master.php.net/note/reject/73216 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123327) next »