hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP ereg Help
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

PHP ereg Help

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-12-2003, 09:57 PM
Mexico Joe Mexico Joe is offline
Junior Guru Wannabe
 
Join Date: Dec 2002
Posts: 72

PHP ereg Help


My regular expression skills are pretty rusty. If I have a line like this:

Sep 12 16:14:34 test xinetd[870]: START: smtp pid=620 from=123.231.123.231

and I want to extract only the IP address at the end, how do I do this with ereg? I tried:

ereg("from=.*", $line, $array)

but this returns "from=123.321.123.321" and I want the IP only without the "from=". I realize I could strip out the "from=" with str_replace, but it would be nice to do it in one step if possible.

Reply With Quote


Sponsored Links
  #2  
Old 09-13-2003, 02:00 AM
cortices cortices is offline
Junior Guru
 
Join Date: Sep 2002
Location: Dallas, TX
Posts: 205
I haven't tested this at all but perhaps you might try something like this for the regexp...

([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$

That should match 4 sets of 1 or more numeric characters seperated by dots at the end of a string.

__________________
justin 'at' abrogo.com
http://www.abrogo.com
Shared Unix Hosting

Reply With Quote
  #3  
Old 09-13-2003, 02:04 AM
digitok digitok is offline
Web Hosting Master
 
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
If your line is always going to be 'from=[ip]' then you can do:

preg_match('/from=(.*)/',$string,$matches);

$matches[1] will hold the IP.

__________________
nu-metal.org :: coming soon

Reply With Quote
Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?