468,256 Members | 1,426 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,256 developers. It's quick & easy.

grep in php

Hi all..

I've got a name like:

name.surname_tel

I would like to separate the 3 object like:

$var1 = name
$var2 = surname
$var3 = tel

I studied the strrpos() and substr()
but it seems it doesn't work
:(
Jul 17 '05 #1
5 8797
Papa <pa**@noaddr.it> wrote:
name.surname_tel

I would like to separate the 3 object like:

$var1 = name; $var2 = surname; $var3 = tel

I studied the strrpos() and substr()
but it seems it doesn't work
:(


Well those could be used to solve your problem, they do work if you use
them correctly. Show us what you did so far and we may be able to tell
you what you are doing wrong.

Jul 17 '05 #2
Papa wrote:
Hi all..

I've got a name like:

name.surname_tel

I would like to separate the 3 object like:

$var1 = name
$var2 = surname
$var3 = tel

I studied the strrpos() and substr()
but it seems it doesn't work
:(


Well they all work.
Look again at www.php.net

good luck,
Erwin Moller
Jul 17 '05 #3
Papa wrote:
Hi all..

I've got a name like:

name.surname_tel

I would like to separate the 3 object like:

$var1 = name
$var2 = surname
$var3 = tel

I studied the strrpos() and substr()
but it seems it doesn't work
:(


Something like this should work quick... (untested)

$name='name.surname_tel';
if(preg_match('`^[^.]+)\.([^_]+)_(.*)$`',$name,$match)){
$var1=$match[1];
$var2=$match[2];
$var3=$match[3];
}else{
$var1 = $var2 = $var3 = '';
}

--
Justin Koivisto - ju****@koivi.com
http://koivi.com
Jul 17 '05 #4
Why don't you try explode? Something like this

$var="name.surname_tel";
$tmp1=explode("_",$var);
$var_tel=$tmp1[1];
$tmp2=explode(".",$tmp1[0]);
$var_name=$tmp2[0];
$var_surname=$tmp2[1];
Ovidiu
-----------------------------------
http://www.DevPlug.com -- Connecting Developers
Jul 17 '05 #5
On 2005-03-31, Papa <pa**@noaddr.it> wrote:
Hi all..

I've got a name like:

name.surname_tel

I would like to separate the 3 object like:

$var1 = name
$var2 = surname
$var3 = tel


Assuming that "." and "_" only appear as separators, you could do:

list($name, $surname, $tel) = split("[._]", $input);

-philip
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by sf | last post: by
2 posts views Thread by John E. Jardine | last post: by
1 post views Thread by Al Belden | last post: by
3 posts views Thread by David Isaac | last post: by
4 posts views Thread by agarwalpiyush | last post: by
15 posts views Thread by tereglow | last post: by
3 posts views Thread by MyMarlboro | last post: by
13 posts views Thread by Anton Slesarev | last post: by
47 posts views Thread by Henning_Thornblad | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.