Re: [PHP] filtering out text in a string
Merlin wrote: Hi there, I want to filter out ip adresses out of a given text string. They are inside a logfile and values are seperated by tabs. I tryed sub_str which works fine if you know the length of the characters. In case of the ip adress this is not the case, since they are sometimes shorter than others. Has anybody an idea how to filter the ip adress out? Maybe magically with any regex or somehow with tab recognicion. This is an example of parts of the text 20:03:20[MSG] 192.168.0.129 bla bla Given: Output is : Array ( [0] => 20:03:20 [1] => [MSG] [2] => 192.168.0.129 [3] => bla bla ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] filtering out text in a string
On Sunday 19 September 2004 02:40, Merlin wrote: > I want to filter out ip adresses out of a given text string. They are > inside a logfile and values are seperated by tabs. I tryed sub_str which > works fine if you know the length of the characters. In case of the ip > adress this is not the case, since they are sometimes shorter than others. > Has anybody an idea how to filter the ip adress out? Maybe magically with > any regex or somehow with tab recognicion. > > This is an example of parts of the text > 20:03:20[MSG] 192.168.0.129 bla bla > > I am stuck here, maybe someone has a good idea or knows how to do that. A dumb regex like this: (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) ought to be sufficient. It does not check for the validity of the address but it probably shouldn't matter too much assuming the program providing the logs can be relied upon. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Sex appeal is 50% what you've got and 50% what people think you've got -- Murphy's Laws on Sex n7 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] filtering out text in a string
Search preg_replace or preg_match in the manual. Jason Merlin <[EMAIL PROTECTED]> wrote: > > Hi there, > > I want to filter out ip adresses out of a given text string. They are inside a > logfile and values are seperated by tabs. I tryed sub_str which works fine if > you know the length of the characters. In case of the ip adress this is not the > case, since they are sometimes shorter than others. > Has anybody an idea how to filter the ip adress out? Maybe magically with any > regex or somehow with tab recognicion. > > This is an example of parts of the text > 20:03:20[MSG] 192.168.0.129 bla bla > > I am stuck here, maybe someone has a good idea or knows how to do that. > > Thank you in advance, > > Merlin > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] filtering out text in a string
Hi there, I want to filter out ip adresses out of a given text string. They are inside a logfile and values are seperated by tabs. I tryed sub_str which works fine if you know the length of the characters. In case of the ip adress this is not the case, since they are sometimes shorter than others. Has anybody an idea how to filter the ip adress out? Maybe magically with any regex or somehow with tab recognicion. This is an example of parts of the text 20:03:20[MSG] 192.168.0.129 bla bla I am stuck here, maybe someone has a good idea or knows how to do that. Thank you in advance, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php