Member
From: Loughborough, United Kingdom
Registered: 2006-04-14
Posts: 805
I've been thanked 13 times.
Offline
Any ideas?
Say I have a variable in a CSV that reads like FredBlogs_BusinessName it's easy to explode with _ to get name and business name values.
Code: php
$data = explode("_",$data);
$clientname = $data['0'];
$businessname = $data['1'];
What would you suggest doing to take a value of $clientname "FredBlogs" and have it return "Fred Blogs"
My abilities to hunt out a solution today seem to be diminished. Must need more coffee.
Thanks
NoSting Hosting - Brightside Hosting Ltd: Member of Nominet / eNom ETP
^^^ Now with over 400 free templates, ShoutCast, LAME + FFMPeg
Ringtones - Palace Marketing Ltd: D2C and B2B mobile content since 2002
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
two stage approach
regular expression to replace each capital letter with it's self, preceeded by a delimiter, eg
FredBlogs_BusinessName
becomes
|Fred|Blogs_|Business|Name
I've used a pipe here as an example, but it coloud be a space, hypen anything you want.
If it's a space, you can explode, trim and implode again to get a more friendly string - what you do with it is up to you!
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
Using posix (yes, I went away to look this up)
find pattern:[A-Z]
replace string-&
this puts a hypen - before all upper case letters
Code: php
$pattern = "[A-Z]";
$string = "-&";
$new_var = ereg_replace($pattern,$string,$old_var);
Member
From: Loughborough, United Kingdom
Registered: 2006-04-14
Posts: 805
I've been thanked 13 times.
Offline
Northie wrote:
Using posix (yes, I went away to look this up)
Code: php
$pattern = "[A-Z]";
$string = "-&";
WOW! Nice one thanks, I really appreciate the time you spent on digging that up for me! I wasn't thinking along the lines of ereg_replace so my mindset wasn't in regular expression 
It didn't work the way I wanted it to so I played with the string and found that this was what I needed to get the desired results:
Code: php
$old_var = "MaryHadALittleLamb";
$pattern = "[A-Z]";
$string = " \\0";
$new_var = ereg_replace($pattern,$string,$old_var);
echo "$new_var<hr />";
Took me ages to work out that \\0 was what I needed!
Northie, nice one thanks! 
Have a couple of beers on me!
NoSting Hosting - Brightside Hosting Ltd: Member of Nominet / eNom ETP
^^^ Now with over 400 free templates, ShoutCast, LAME + FFMPeg
Ringtones - Palace Marketing Ltd: D2C and B2B mobile content since 2002
| Never |


