Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SplitWords into Split Words 1

Status
Not open for further replies.

bccamp

Technical User
Jan 20, 2005
69
I've tried to figure this out, but I'm stumped. I have combined words like "SplitWords" which I need to make into "Split Words." I've looked at 'split', 'ereg_replace', 'preg_replace' but I'm having a terrible time with the syntax. The best I can do so far is make it " plit ords" with ereg_replace. Please help me with the syntax on this.
 
Let me first define terms. "SplitWords" is a compound word. "Split" and "words" are simple words.

How large a dictionary of compoud words are we talking about? It seems to me that you're first going to have to teach your script every simple word.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thank for replying. I was hoping there was a way to use the [A-Z] to find all words that are Capitalized and separate them. I don't think I made that clear in my original question. I apologize. Is there a way to separate Capitalized words? I thought I was on the right track with ereg_replace, but as I said, I'm having trouble with the syntax. I have a drop down menu with the entries, which I don't want any entry more than 20 characters. So I need to split them somewhere in the middle, where it is capitalized, but I thought I would tackle one problem at a time.

Thanks again.
 
you can use egreplace the same way that you did to take out the UC letters and use " UCletter" in as the replace field in your case you would run it through for each uppercasae letter and the first one would be " S" and the second one would be " W". You can find out which on is upper case but i can't remember how. Then after you get " Split Words" you can trim it to get "Split Words". Do you understand? This will only work if each word begins with an UC letter.

David Kuhn
------------------
 
Something like:

Code:
<?php
$a = 'TheRaininSpainstaysmainlyinthePlain';

$a = preg_replace ('/([A-Z])/' , ' $1', $a);
$a = ltrim($a);

print $a;

?>

Outputs:

The Rainin Spainstaysmainlyinthe Plain


is that what you're looking for?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top