Separate numbers form letters in a php string

Dear All

I am building a system that creates a ror xml file using php and mysql

however becouse I’m not entering the data into the database I can not govern what my php is pulling out.

I seem to have ironed out most of the issues I have come accross like html tags and cutting out unessacery white spaces plus a few other bits but it seems not to like content that has numbers and letters next to each other example “bbbb5555” but “bbbb 5555” is ok

is there a way to sperated text from letters in a php string using php?


$str = "bbbb5555";
echo preg_replace('/[a-z](?=\\d)/i', '$0 ', $str);

Thanks stereofrog

thats work for that string “bbbb5555” but not if the string is more complex

I need it to reconise any number of letter charaters that are next to a number so if we had “bb22cc33dd44EE55FF66” i would get “bb 22 cc 33 dd 44 EE 55 FF 66”

I’ve had a look at the php.net site preg_replace and Pattern Syntax but struggling to peace it together.

Lets try this expression


/[a-z](?=\\d)|\\d(?=[a-z])/i

In case you’re wondering what does this mean


[a-z] # a letter
(?=   # followed by
\\d    # a digit
)
|     # or 
\\d    # a digit 
(?=   # followed by
[a-z] # a letter
)

Thanks Stereofrog your a star
That works a treat and I understand it a little better with your break down