Forum Moderators: coopster

Message Too Old, No Replies

string function

         

Heeren

11:56 am on Aug 28, 2006 (gmt 0)

10+ Year Member



hi
please tell me how to split a string in two string in php, is there any string function for this? EX. i want to brake a name in to first and last name (eg, Heeren Tana, fname=heeren and lname= tana ), please help me , i am creating a search form for searching by either fname or last name or by both name

please reply thanks

barns101

12:02 pm on Aug 28, 2006 (gmt 0)

10+ Year Member



If it's a simple split (e.g. separate two parts when a space is encountered), take a look at explode() [php.net]. If you want to use regular expressions when isolating the parts, look at split() [php.net].

Psychopsia

11:54 pm on Aug 28, 2006 (gmt 0)

10+ Year Member



You can use the explode() function:

$str = 'Heeren Tana';
$words = explode($str, ' ');

The $words will be an array like this:

array(0 => 'Heeren', 1 => 'Tana')

Psychopsia

2:14 pm on Aug 29, 2006 (gmt 0)

10+ Year Member



Sorry, my explode function is wrong.

Here's the correct:

explode($separator, $str[, int limit])

$str = 'Heeren Tana';
explode(' ', $str);