Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eregi_replace and other regex's

Status
Not open for further replies.

vcherubini

Programmer
May 29, 2000
527
US
I am having trouble working with the regi_replace and eregi_replace functions.

I have a mySQL dbase that I read a time from. The time is inputed in the form hms, or hours minutes seconds. When I read the value from that field, I get some huge number, such as 33045, meaning it is 3:30 and 45 seconds.

I am wondering how I can use the above mentioned functions or another function to extract the first number, the second and third numbers, and the fourth and fifth numbers.

Any help is appreciated.

Thanks,

-Vic

vic cherubini
malice365@hotmail.com
====

Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director

Wants to Know: Java, Cold Fusion, Tcl/TK

====
 
If all you want to do is extract pieces of the field, why are you using "_replace" functions? Why not use "substr" like:

$huge_number = 33045;
$hours = substr($huge_number,0,1);
$minutes = substr($huge_number, 1,2);
$seconds = substr($huge_number,3,2);

I'm sure there's a more efficient way to do that, but regi_replace and eregi_replace seem like the wrong choices to me.
Hardy Merrill
Mission Critical Linux, Inc.
 
Ahh, I see now.

Thanks a bunch for that, I was not thinking clearly when I tried to use the other functions.

It worked perfectly. Thanks,

-Vic
vic cherubini
malice365@hotmail.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top