Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How to loop a compressed file in php?

loop

  • Please log in to reply
11 replies to this topic

#1 onething

onething

    CC Addict

  • Validating
  • PipPipPipPipPip
  • 125 posts

Posted 21 August 2012 - 03:13 AM

<?
$target[0]="aaa";
$target[1]="bbb";
$target[2]="ccc";

would be too cumbersome to write on each page of code.


$target = array ("aaa","bbb");

would be better, but still doesn't allow for an easy import of all the values.

strpos or strtolower is probably the solution


<?php
$mystring = 'aaabduekf';
$findme = 'aaa';
$pos = strpos($mystring, $findme);
if ($pos === false) {


I wanted to ask how would I loop this strpos to all the strings in my list of IPs? Should I resort to counters in php, or is there a getblock of text equivalent in php? All I know about in php is the str but that applies to strings, not blocks.


While I'm here, the geoip.dat file created by maxmind seems to have 16 million c classes sitting in a dat file not even 1mb in size. How did the guy do it? I don't know given that its encrypted, but it would be nice to know how to run a loop through a compressed file like this one.
  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 21 August 2012 - 03:40 AM

I don't think he stored classes there, just well structured data.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 onething

onething

    CC Addict

  • Validating
  • PipPipPipPipPip
  • 125 posts

Posted 21 August 2012 - 05:22 AM

What do you mean you don't think he stored classes? What did he store there instead? You think he reduced it drastically by identifying ranges of c classes that were of the same country?

And what about identifying all the strings in a block of text to have or not have ''abc''? I only know about str in php
  • 0

#4 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 21 August 2012 - 05:38 AM

It's probably stored in ranges of formerly called C-nets together with coordinates and location as a string.

about your other issue, what do you mean by strings in a block of text in php? php has strings and array of strings. there is not block of text more than a very long string. Do you want to find in which sentences your string appear?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#5 onething

onething

    CC Addict

  • Validating
  • PipPipPipPipPip
  • 125 posts

Posted 21 August 2012 - 07:09 AM

I have a list of strings. Then I have a constantly changing value I would like to know whether it's inside that list or not. The constantly changing value is usually abc, or abd, whereas the list consists of words like abcdef or dzxrf. I can make a list of $target, as above, with each of the strings of the list but it would be messy and I would always have to write each string into each ''$target''. I could also make an array, as above, but that too would mean I wouldn't be able to easily add strings to my list, I would have to add them inside those brackets and inside the quotes.

So I'm looking for a way to just include a list of strings into a php statement, for the constantly changing value to be looped through that list to see if it's present or not. I have experience with another language which isn't really a programming language, it's more like a GUI, called zennoposter, and there we have counters to run through a list, you increase the counter and you can identify the string number that's equivalent to that counter, extract that string and see if it contains the constantly changing value, right up until the end of the file full of strings you want to explore.

But in php, I only know about str search, but that searches one string at a time. Is there a way to run through an entire block of text (while honoring string end lines and new lines).

On the other subject, are cnets not the same as clcasses?
  • 0

#6 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 21 August 2012 - 07:42 AM

"list" in php is a function creating an array. is it an array of strings you're using?
if so, this comment to a php function might help you: http://www.php.net/m...arch.php#100065

c-net or c-class-net was more or less synonyms, but the term is obsolete now, now, you only talk about it's netmask to identify the size of a net. for example 192.168.0.0/24 means 192.168.0.0--192.168.0.255 while 192.168.0.0/23 means 192.168.0.0--192.168.1.255 or maybe 192.168.10.24/30 means 192.168.10.24--192.168.10.27

a /30 is the smallest possible network with IPv4 and it can be on a totally different geographical location than it's numeric neighbor.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#7 onething

onething

    CC Addict

  • Validating
  • PipPipPipPipPip
  • 125 posts

Posted 21 August 2012 - 09:36 AM

Ok, I didn't mean 'list' as in a function in php.
Yes it's an array, but I can't be importing my list into an array. I want something better than array. I just want it to be a plain text file the php can go through. Or a plain php file I can include. Something simpler than having to build arrays that have to have all my strings placed in between commas, apostrophes, inside brackets and whatnot.

The example you gave me, is it referring to previous variables or arrays declared on the page by other people's comments? I can understand it up to the point he claims $key plus $haystack_array is $eval, because I only know one of the three variables $haystack_array from a previous line. Then it declares a variable called $arr that's an array of what seems like the values I would input of the haystack, and I was looking to avoid arrays, I am looking for something simpler than having to input all my values inside brackets, apostrophes and commas.
  • 0

#8 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 21 August 2012 - 11:06 AM

it's a function which you call with your array (haystack) and your search (needle), and it returns true if it's found.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#9 onething

onething

    CC Addict

  • Validating
  • PipPipPipPipPip
  • 125 posts

Posted 21 August 2012 - 11:25 AM

my_array_search is the function, but what are $key, $eval and $arr? Is $arr an array of the values inside $haystack_array? I'm looking for something easier to read and write than an array, something where I could cycle through a text or include a page
  • 0

#10 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 21 August 2012 - 11:29 AM

the whole is the function. it does that, checks all the array if there is something of the needle in the haystack.

the foreach loops through the array and for each post in the array, it checks if the needle is in that string.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#11 onething

onething

    CC Addict

  • Validating
  • PipPipPipPipPip
  • 125 posts

Posted 21 August 2012 - 11:36 AM

How can I get $haystack_array to be a text file? As I said above, right now to create an array, I only know of

$arr = array('foo', 'bar');

and


$target[0]="aaa";
$target[1]="bbb";
  • 0

#12 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 21 August 2012 - 01:55 PM

use the file function to read a file to an array: http://www.php.net/m...nction.file.php
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.






Also tagged with one or more of these keywords: loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download