note 123570 added to function.ucwords
| From: | codemilitant at gmail dot com | Date: | Thu, 31 Jan 2019 00:25:38 +0000 |
| Subject: | note 123570 added to function.ucwords | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210147@lists.php.net to get a copy of this message | ||
When updating titles of web pages and posts, I found it much faster, and very easy to take advantage
of the str_ireplace array search capabilities. This simple function will find only those words you
wish to leave in lowercase (or uppercase), and do so with the speed of str_replace instead of any
regular expressions.
When run, the str_ireplace case insensitivity only applies to the search. When found, it replaces
with the word as it's typed in the very same array. Since this project was for web
development, I added the ";" and ">" to the ucwords capabilities.
Just be sure the words in the delimiters array are the proper case to get the desired results.
$title = "Building And CREATING Great Seo WebSites";
function ucproper($string) {
$string = ucwords( strtolower(trim($string)), ";> \t\r\n\f\v" );
$delimiters = [ 'and', 'but', 'or', 'of', 'to',
'SEO' ];
$string = str_ireplace( $delimiters, $delimiters, $string );
return $string;
//this returns lowercase (or uppercase) delimiter word found in string using those same delimiters
as a case insensitive search
}
echo ucproper($title);
//Building and Creating Great SEO Websites
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.35 (proxied: 216.41.249.178)
----
Manual Page -- http://php.net/manual/en/function.ucwords.php
Edit -- https://master.php.net/note/edit/123570
Del: integrated -- https://master.php.net/note/delete/123570/integrated
Del: useless -- https://master.php.net/note/delete/123570/useless
Del: bad code -- https://master.php.net/note/delete/123570/bad+code
Del: spam -- https://master.php.net/note/delete/123570/spam
Del: non-english -- https://master.php.net/note/delete/123570/non-english
Del: in docs -- https://master.php.net/note/delete/123570/in+docs
Del: other reasons-- https://master.php.net/note/delete/123570
Reject -- https://master.php.net/note/reject/123570
Search -- https://master.php.net/manage/user-notes.php