Food And Beverage
Uk Transport
These are terms that Capitalized text-transform is messing up for us.
We force the insert for the name to be lowercase, so it's shows lowercase in the URL.
We don't use slugs. So if they add "my web site" as the title, then the url is "my-web-site".
Is there a text transform that identifies the words someshow, so it knows UK is UK and not Uk, and the same for And If On Was... etc??
Can you set the casing but ignore non titles?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Can you set the casing but ignore non titles?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Can you set the casing but ignore non titles?
Not built-in. Consider "ME": how would anything know whether that's the pronoun or the notoriously buggy edition of Windows?
Rather than lowercase and re-capitalize words, how about specifically capitalizing lowercase words and specifically lowercasing some capitalized words? Confusing?
Lowercasing and then capitalizing:
Capitalizing and then lowercasing:
1. Note that those regexes are using a space to indicate the beginning or end of a word.
2. Note that the second regex will deliberately not lowercase a common word if it's at the beginning of the string.
Rather than lowercase and re-capitalize words, how about specifically capitalizing lowercase words and specifically lowercasing some capitalized words? Confusing?
Lowercasing and then capitalizing:
Code: Select all
// do some general cleanup on the string first
$input = trim("UK Transport");
// lowercase everything and lose all the capitalization in "UK"
$output = strtolower($input);
// only regain the first letter of it
$output = ucwords($output);
echo $output;Code: Select all
// do some general cleanup on the string first
$input = trim("UK Transport");
// keep all existing capitalization and "fix" something that had a leading lowercase letter
$output = preg_replace_callback('/(^|\s)[a-z]/', function($match) { return strtoupper($match[0]); }, $input);
// "fix" (or perhaps un-fix from the previous step) a known common word with a leading uppercase letter
$output = preg_replace_callback('/(\s)(and|if|on|was|...)(\s|$)/', function($match) { return strtolower($match[0]); }, $output);
echo $output;2. Note that the second regex will deliberately not lowercase a common word if it's at the beginning of the string.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Can you set the casing but ignore non titles?
Think I might change the system and use slugs from the database, to manage the urls.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Can you set the casing but ignore non titles?
That's a very good idea.