Re: Converting a string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Well, you didn't answer the second question, how would you do it? So far I see a pattern: "ignore the lowercase letters at the beginnig and add a space before an uppercase" (this won't apply to all field names, and I hope you're aware of that), so try something like
  $text = preg_replace('/^[a-z]+\s*/X', '',
                       preg_replace('/(?=[A-Z])/X', ' ', $name) );

Now, a better way, IMHO, would be to use "_" as spaces and write the name of the field as you want it to appear (e.g. "First_Name"), so you just need to
  $text = str_replace('_', ' ', $name);
--pretty much simplier, isn't?
And... if you want to add a prefix (such as "ps") then make it configurable, so it can be changed anytime without effort.

Last comment: you should think about the question you didn't answer, and that might give you the solution to your problem.

Jay Blanchard wrote:
[snip]
	Then you should change the name of the field.  Seriously, what
do you expect the script to do, exactly? and once you know the answer, what would you do to achieve that? Put that (emphasis to the second question) in words and someone might be able to help you.
[/snip]

I expect that I can take a string, like 'psFirstName' and change it to
'First Name'. that way I don't have to worry about what some web
designer named his fields, I can turn them into human readable strings
without having to manually create a new array.

So far I have this

$newKey = preg_split("/([A-Z])/", substr($key, 2), -1,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

Which returns;

Array
(
    [0] => F
    [1] => irst
    [2] => N
    [3] => ame
)
--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
http://www.innox.com.mx

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux