PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Oct 15, 2018 11:10 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Mar 18, 2016 12:44 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4425
Location: United Kingdom
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??

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Fri Mar 18, 2016 12:58 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
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:
Syntax: [ Download ] [ Hide ]
// 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;


Capitalizing and then lowercasing:
Syntax: [ Download ] [ Hide ]
// 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;


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.


Top
 Profile  
 
PostPosted: Fri Mar 18, 2016 6:27 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4425
Location: United Kingdom
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.


Top
 Profile  
 
PostPosted: Fri Mar 18, 2016 11:11 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
That's a very good idea.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group