Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    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.

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,798
    Thanks
    19
    Thanked 156 Times in 147 Posts
    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 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •