Re: how to parse a string parse with ereg

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

 



Hi,

> I have to admit I'm not following you. My suggestion that you use explode() 
> was based on the premise that you have a bunch of lines:
> 
> ...
> xxx.x.x.x   0.0.0.0 255.255.255.255 UH 0      0        0 ppp0
> 192.168.0.0 0.0.0.0 255.255.255.0 U    0      0        0 eth1
> 0.0.0.0     xxx.x.x.x 0.0.0.0     UG   0      0        0 ppp0
> ...
> that are currently stored in a string. After explode() you can use foreach() 
> to loop through the array and check each line individually. Then based on 
> whether the line passes the check you could either:
> 
> a) unset that array element (doesn't pass check so get rid of it)
> or
> b) copy that element to a new array (passes check so store it in a 'good' 
> array)
> Either way you'll end up with an array containing only 'good' lines.

Well this work's fine in the case the user input is correct :-)

But it's not required to proof in the case I would assume that a
user input is correct.

To explode with the device as line break to allocate an array mem 
lead's not to an error as this line it won't be in the array.

xxx.x.x.x |  0.0.0.0 255.255.255.255 UH 0 |  |  | 0 |  |  |  | 0 ppp0
192.168.0.0 0.0.0.0 255.255.255.0 U |  | 0 |  |  | 0 |  |  |  | 0 eth1
0.0.0.0 |  |  xxx.x.x.x 0.0.0.0 |  |  UG |  0 |  |  | 0 |  |  |  | 0

E.g. Line 3 won't be in an array. This could maybe be caused from 
drop & paste to copy from a shell into the browser while using
an extraordinary OS.

***
The only solution which should be better now for me is to proof
for 3 ip addresses in a row to be able to count how much
of this matching construct in a result is as basis for a difference. 
Then I'am able to compare this with matching lines where the 
device has been taken to explode.

The difference lead's now to an error as the syntax is wrong.

The only problem which still remains is the case the device 
is missing __AND__ there're not 3 following ip addresses. This user
input data is not going to be proofed but it seems to be better 
than before.

And for sure normally the user input should be correct :-) 

-- 
Best Regards, 

Mark 

-- 
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