FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


split and trim?





kk_loke86
Hello, I am trying to split the following text into arrays, but I can`t knock out those extra spaces even using split, trim and explode. Can anyone help me?

ID 104K_THEAN Reviewed; 893 AA.

What I want is something like this in the end:

Array ([0] => ID, [1] => 104K_THEAN, [2] => Reviewed;, [3] => 893 AA)
kk_loke86
The original text should contain more spaces as shown above.

* represent the spaces,

ID***104K_THEAN*************Reviewed;*********893 AA.
sonam
You can replace few spaces with one space using str_replace function:

Code:
$string= str_replace('  ',' ',$string);  // first one is double space second is single


I think how is explode the simplest way to get array from string.

Sonam
alalex
ANother way to do that would be to first explode by the ; And then you would have:
ID 104K_THEAN Reviewed
And
893 AA
And now explode the first line using the space as separator, and then trim the second line and add it to the original array Wink

If you want the semicolon in the first line just concatenate it
Related topics
[php scripts ] phpweather&email
got this error..
Executing a .sql file through PHP
Frankfurt Motor Show, 2005
Ultra Video Splitter 3.0.8
How do i split up my server space?
Split Computer Hardware and Software Forum
Cutting length
idlewild split from record label
Split the forum up (Questions vs News)
sms jokes
sms jokes
What is the best way to split up?
help me split my *.ISO
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.