Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-26-2012, 09:18 AM   PM User | #1
shajiuddin
New Coder

 
Join Date: Sep 2011
Posts: 69
Thanks: 6
Thanked 0 Times in 0 Posts
shajiuddin is an unknown quantity at this point
Change String format

Hi,

I need to change string format like every first letter of word should be in capital and '.' should be replace with space ' ' and this string may be any format

For example: 'bret.blunt' or 'BRET BLUNT' or 'BretBlunt' or 'BrRtBlUnT' should be 'Bret Blunt'

Which function I have to to use please help

Regards
shajiuddin is offline   Reply With Quote
Old 04-26-2012, 10:11 AM   PM User | #2
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,460
Thanks: 89
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
Use a collection of functions

PHP Code:

$bar 
"BRET.BLUNT";
$bar ucwords(str_replace(".",""strtolower($bar))); 
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 04-26-2012, 10:14 AM   PM User | #3
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Quote:
Originally Posted by shajiuddin View Post
Hi,

I need to change string format like every first letter of word should be in capital and '.' should be replace with space ' ' and this string may be any format

For example: 'bret.blunt' or 'BRET BLUNT' or 'BretBlunt' or 'BrRtBlUnT' should be 'Bret Blunt'

Which function I have to to use please help

Regards
You're going to run into problems with 'BrRtBlUnT' because there is no logical separation between 'Bret' and 'Blunt'.

For the other strings you have a period, space, and Pascal casing respectively to identify the break in the string.

So before I even attempted to address your original question, I think it would be best if you first narrowed down 'any format' to at least a group of formats that contain identifiable and/or common patterns -- that we can then apply some regular expression or series of PHP functions to, to solve your problem.
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:43 AM.


Advertisement
Log in to turn off these ads.