471,093 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,093 software developers and data experts.

How to split a string which is having two spaces

250 100+
I want to split a string which is having two space. I'm using php.
ex: test test2
(between test and test2 have two spaces). Could someone help me?
Aug 6 '08 #1
2 1855
hi qhjk

you can split two string with space using php explode() function in this u have to pass two parameters first string separate delimiter in ur case its space and second is ur string string .

explode function return u and array of separated string

Expand|Select|Wrap|Line Numbers
  1. $sample="i am learning php";
  2. $separated=explode(" ",$sample);
  3. echo $separated[0]."<br>";
  4. echo $separated[1]."<br>";
  5. echo $separated[2]."<br>";
  6. echo $separated[3]."<br>";
Aug 6 '08 #2
5,821 Expert 4TB
Heya, ghjk.

Try preg_split() (http://php.net/preg_split):
Expand|Select|Wrap|Line Numbers
  1. $split = preg_split('/\\s+/', $str);
Aug 6 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Stu Cazzo | last post: by
5 posts views Thread by Robert Oschler | last post: by
2 posts views Thread by SL_McManus | last post: by
4 posts views Thread by dchan1 | last post: by
3 posts views Thread by John Salerno | last post: by
2 posts views Thread by Martin Arvidsson, Visual Systems AB | last post: by
10 posts views Thread by teddyber | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.