Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Split a string - or can you?

Links for php scripts

Moderators: macek, egami, gesf

Split a string - or can you?

Postby ddrake1984 » Wed Mar 21, 2012 7:53 pm

I need to split a string, but in a very unusual way.

$string1 = "HelloWorld"
$string2 = "AlphaBravo"
$string3 = "BreakMeUp"

I need the following split at each upppercase letter for this output

Hello World
Alpha Bravo
Break Me Up
ddrake1984
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Mar 21, 2012 7:51 pm

Re: Split a string - or can you?

Postby egami » Thu Mar 22, 2012 4:05 am

Investigate strpos()

php.net/strpos
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Split a string - or can you?

Postby ddrake1984 » Thu Mar 22, 2012 2:05 pm

I received the assistance I needed from phpfreaks.com

$string = 'ThisText';

$newstring = '';
foreach( str_split( $string ) AS $letter ) {
$newstring .= ( ctype_upper( $letter ) ? ' ' : '' ) . $letter;
}
$string = trim( $newstring );
ddrake1984
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Mar 21, 2012 7:51 pm


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron