Re: how to parse a string parse with ereg

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Friday 19 November 2004 01:50, Mark-Walter@xxxxxxxxxxx wrote:

> > Then you can process each line separately but in groups 3 lines at a time
> > (assuming they're supposed to be groups of 3).
>
> but what happen's in the case a user drop down every line in a web
> form without a ELO character ?

Not quite sure what you mean here. In a <textarea> pressing ENTER/RETURN will 
generate an EOL character. If they have a habit of not pressing ENTER/RETURN 
when they should then you can run a simple check on the length of a line and 
reject and/or ask them to enter again.

In any case if you want to force the user to enter lines separately use a 
bunch of <input type="text" ...> instead of <textarea>.

The point here is that doing relatively simple checks early on in the data 
entry stage to ensure that you get sane data means you don't have to trawl 
through garbage in the data processing stage trying to figure out all the 
ways in which a user could have entered incorrect data.

> > If you state clearly, in detail, what exactly you want the regex
> > to match then
> > maybe someone could construct a better one for you.
>
> Ok, at the moment I verify the assuming missed device with a difference
> of the following both block's:

[...]

You're telling us what you're *doing*, not what you *want* your code to do. We 
need to know what you *want* your code to do before we can suggest 
improvements or whatever.

Anyway here's a PCRE to match a single IP address:

(([0-9])|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))\.(([0-9])|([1-9]
[0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))\.(([0-9])|([1-9][0-9])|(1[0-9]
[0-9])|(2[0-4][0-9])|(25[0-5]))\.(([0-9])|([1-9][0-9])|(1[0-9][0-9])|(2[0-4]
[0-9])|(25[0-5]))

It will validate an IP address of the form:

  (0-255).(0-255).(0-255).(0-255)

No leading zeros allowed.

> <?
> $INET_NUM_exp = ereg_replace("[\
> ]+([a-z]+)([0-9]{1})","\\1\\2_XrR",$INET_NUM); $sorter =
> explode("_XrR",$INET_NUM_exp);
> $result = count($sorter);
> $result = $result-1;

Instead of doing this bit of code (which I don't understand), I suggest that 
you incorporate some simple check for interface into your regex:

(((eth|ppp)\d{1,2})|lo)


-- 
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
------------------------------------------
/*
Bloom's Seventh Law of Litigation:
 The judge's jokes are always funny.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux