SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: possibly a preg_match issue??
Hybrid View
-
Jun 8, 2009, 19:04 #1
- Join Date
- Jun 2007
- Location
- North Richmond
- Posts
- 495
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
possibly a preg_match issue??
G'day to all,
I am trying to work on a solution to this problem and I am getting all mixed up with my php functions.
I use camelCasing for my file names and I would like to output the file names as readable text.
E.G.
"contactUs"
I would like to have it as:
"Contact Us"
What expression or function would I need to allow this function to work? With the forsight of different file names,
E.G.
pageTypes => Page Types
Many thanks in advanceRegards,
BJ Duncan
-
Jun 8, 2009, 19:18 #2PHP Code:
<?php
$s = 'pageTypes';
$s = preg_split( '/([A-Z][^A-Z]+)/', $s, -1, 3 );
echo ucwords( join( $s, ' ' ) );
-
Jun 8, 2009, 19:28 #3
- Join Date
- Jun 2007
- Location
- North Richmond
- Posts
- 495
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Many thanks for your assistance logic_earth
Works like a charm. I think I was getting my functions all mixed up. I was trying to use preg_match but was getting myself all mixed up.
Thank you.Regards,
BJ Duncan
-
Jun 9, 2009, 04:48 #4
An alternative would be to match Capitalized words and prefix them with a space (then make sure the first letter of the string is also uppercase).
PHP Code:<?php
$s = 'pageTypes';
echo ucfirst(preg_replace('/[A-Z][^A-Z]*+/', ' $0', $s));
Bookmarks