Hi everybody, I am trying to write a code which record a CIDR (5.2.80.0/21 5.11.128.0/17) format ip list into mysql database. I have a problem at one part of my code. Code is the below. With this code I am trying to find every third "." character's place and every "/" character's place and every " " characters place. After finding the places the code record the places in to an array which name is $reference_points. The problem is that for exaple if I apply this code on this 5.2.80.0/21 5.11.128.0/17 string. The result should be $reference_points.[1]=7 $reference_points.[2]=9 $reference_points.[3]=12 but it shows $reference_points.[1]=7 $reference_points.[2]=9 $reference_points.[3]=23. And the full list of CIDR ip is attached. By the way I use a form on php page to take this list. The code part is which start fith FOR loop. Thak you very much.
<div align="center"><form action="add_new_country.php" method="post"><table><tr><td>Country name:</td> <td><input type="text" maxlength="50" name="new_country_name" id="new_country_name" size="38" /></td></br></br></tr><tr><td>Country Ip Ranges:</td> <td><textarea rows="10" cols="30" name="country_ip_ranges" id="country_ip_ranges"> </textarea></td></br></br></tr><tr><td><input type="submit" name="submit" value="Add New Country" /></td><td></td></tr></table></form></div> <div align="center"><?phpif(isset($_POST["new_country_name"]) && isset($_POST["country_ip_ranges"]) && !empty($_POST["new_country_name"]) && !empty($_POST["country_ip_ranges"])){$country_name=@$_POST['new_country_name'];$country_ip_range=@$_POST['country_ip_ranges']; $sql=mysql_query("SELECT id FROM countries WHERE country_name='$country_name' LIMIT 1");$exist_count=mysql_num_rows($sql); if($exist_count==1){echo "The name of the country which you try to add is already exist in the system, please try to add different name.";}else{mysql_query("INSERT INTO countries (id,country_name) VALUES ('','$country_name')" );mkdir("$country_name");$dot=0;$reference_points=array();$reference_points_index=1; for($i=1;$i<=strlen(trim($country_ip_range));$i++){if(substr(trim($country_ip_range),$i-1,1)=='.' && $dot<3){$dot=$dot+1; if($dot==3){$reference_points[$reference_points_index]=$i;$dot=0;$reference_points_index=$reference_points_index+1;} }elseif(substr(trim($country_ip_range),$i-1,1)=='/'){$reference_points[$reference_points_index]=$i;$reference_points_index=$reference_points_index+1; }elseif(substr(trim($country_ip_range),$i-1,1)==' '){$reference_points[$reference_points_index]=$i;$reference_points_index=$reference_points_index+1;}}echo $reference_points[1].'<br/>';echo $reference_points[2].'<br/>';echo $reference_points[3].'<br/>';echo $reference_points[4].'<br/>';echo $reference_points[5].'<br/>';echo $reference_points[6].'<br/>';echo $reference_points[7].'<br/>';echo $reference_points[8].'<br/>';}}?></div>
TR_cidr.txt