473,226 Members | 1,327 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 8946
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: sf | last post by:
Just started thinking about learning python. Is there any place where I can get some free examples, especially for following kind of problem ( it must be trivial for those using python) I have...
2
by: John E. Jardine | last post by:
Hi, Problem: Executing 's///' has a side effect on grep null string matching. If line 62, the substitution, is executed the last two values returned by grep and printed on lines 68, 69 are...
1
by: Al Belden | last post by:
Hi all, I've been working on a problem that I thought might be of interest: I'm trying to replace some korn shell scripts that search source code files with perl scripts to gain certain features...
3
by: David Isaac | last post by:
What's the standard replacement for the obsolete grep module? Thanks, Alan Isaac
4
by: agarwalpiyush | last post by:
Hello, I am going nuts with trying to get the following to work: This is what I intend to do: I have a line in /etc/syslog.conf which I need to delete based on ip-address provided to me in a...
4
by: js | last post by:
Just my curiosity. Can python beats perl at speed of grep-like processing? $ wget http://www.gutenberg.org/files/7999/7999-h.zip $ unzip 7999-h.zip $ cd 7999-h $ cat *.htm bigfile $ du -h...
15
by: tereglow | last post by:
Hello all, I come from a shell/perl background and have just to learn python. To start with, I'm trying to obtain system information from a Linux server using the /proc FS. For example, in...
3
by: MyMarlboro | last post by:
print Dumper(@data); _____________ $VAR1= '2008,Car,Medium1,5000'; $VAR2= '2008,Car,Medium2,5000'; $VAR3= '2007,Plane1,Medium1,20000'; $VAR4= '2006,Boat,Small1,20000'; $VAR5=...
13
by: Anton Slesarev | last post by:
I've read great paper about generators: http://www.dabeaz.com/generators/index.html Author say that it's easy to write analog of common linux tools such as awk,grep etc. He say that performance...
47
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.