...

View Full Version : Change String format



shajiuddin
04-26-2012, 10:18 AM
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

timgolding
04-26-2012, 11:11 AM
Use a collection of functions




$bar = "BRET.BLUNT";
$bar = ucwords(str_replace(".","", strtolower($bar)));

chump2877
04-26-2012, 11:14 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum