magic2goodil Posted January 11, 2007 Share Posted January 11, 2007 I am trying to take this document.[url=http://www.collegebookx.com/text.txt]http://www.collegebookx.com/text.txt[/url]and then with ereg and preg statements I am eventually going to pull out just the college names.but right now it is failing my teststhe live code is here: [url=http://www.collegebookx.com/process.php]http://www.collegebookx.com/process.php[/url]can you tell me why it might be suddenly messing up at 311?does anyone have a better suggestion for how to do this thing?here is the code for process.php:[code]<?php$handle = @fopen('text.txt', "r");if ($handle) { while (!feof($handle)) { $lines[] = fgets($handle, 2827); } fclose($handle);}$i = 0;while($i < count($lines)) {$string = $lines[$i];ereg(">.*</H2>", $string, $ar);if(ereg(">.*</A>", $string, $arr)) {foreach($arr as $a) {$pattern = "/><A\sHREF=\"http:\/\/(.+)\/\"\sTARGET=\"_blank\">/";$replacement = "";$a = preg_replace($pattern, $replacement, $a);$a = eregi_replace("[^[a-z][</A>]{1}]", "", $a);$a = eregi_replace("</A>", "", $a);$lines[$i] = $a;}}echo $i . "=" . $lines[$i] . "<br>";$i++;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/ Share on other sites More sharing options...
magic2goodil Posted January 11, 2007 Author Share Posted January 11, 2007 i know someone can figure this out :P Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158134 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 Maybe if you gave them longer than 10 minutes before re-posting they'd be more inclined to helpHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158139 Share on other sites More sharing options...
magic2goodil Posted January 11, 2007 Author Share Posted January 11, 2007 lol, my bad :PI appreciate any effort you are inclined to put forth. :) Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158141 Share on other sites More sharing options...
magic2goodil Posted January 11, 2007 Author Share Posted January 11, 2007 -Bump Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158157 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 Don't bump your post this soon!Remember that people viewing this board are based all over the world, mainly in the US, so many of them haven't even seen your post yet. I think you should wait at least 4 hours before bumping your post.Now what exactly do you want? If it's just a list of the Uni's then this will do it...[code]<?php// Open the file$fh = file_get_contents('http://www.collegebookx.com/text.txt');// Define the pattern$pattern = '|blank">(.*?)</A>|';// Match patern and place into an arraypreg_match_all($pattern, $fh, $matches);// Echo the listforeach ($matches[1] as $u){ echo "$u<br>\n";}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158165 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 I've been hacking away and this code will give you an array keyed on state... the value of this array is another array keyed numerically with the values as the colleges...[code]<?php// Open the file and get the contents into a single string$fh = file_get_contents('http://www.collegebookx.com/text.txt');// Define the pattern for matching the states and colleges$pattern = '|<H2.*?">(.*?)</H2>(.*?all">)|s';// Match patern and place into an arraypreg_match_all($pattern, $fh, $matches);// Sort the matches into seperate arrays$states = $matches[1];$collegelinks = $matches[2];// Loop through each state and get the colleges for itforeach ($states as $n => $s){ // Define the pattern for matching the colleges without the http link $pattern = '|blank">(.*?)</A|s'; // Match patern and place into an array preg_match_all($pattern, $collegelinks[$n], $c); // Insert the colleges into arrays keyed on state $complete_list[$s] = $c[1];}// Sort the array alphabetically on stateksort($complete_list);//Print the list...foreach ($complete_list as $s => $cl){ echo "<p>\n"; echo "<b>$s</b><br>\n"; foreach ($complete_list[$s] as $c){ echo "$c<br>\n"; } echo "</p>\n";}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158289 Share on other sites More sharing options...
magic2goodil Posted January 11, 2007 Author Share Posted January 11, 2007 hey, thanks alot man, I'll try this code out now.Sorry if I seemed impatient, excuse me, was impatient last night. It was about 6am and I wanted to get this but I wanted to goto bed, lolAnyways, I'll let you know how this works, thanks alot. Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158476 Share on other sites More sharing options...
magic2goodil Posted January 11, 2007 Author Share Posted January 11, 2007 Wow, you rock dude.That code works awesome.I'm going to study your pregs and such to understand them better and then work on pulling out the tags next to the States and also try and make a small array of what those damned & and such mean so I can successfully change those to actual charactersYour help is very much appreciated :) Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158481 Share on other sites More sharing options...
magic2goodil Posted January 11, 2007 Author Share Posted January 11, 2007 After reviewing your code, excuse my ignorance for thinking that you hadn't cut out the tags. You have, it works perfect.Thanks alot Huggie. Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158507 Share on other sites More sharing options...
HuggieBear Posted January 12, 2007 Share Posted January 12, 2007 Don't worry about the 'bumping' thing, it's just one of those pet hates of mine... The forum does allow bumping and in the posting guidelines it says 'after a few hours' so no harm done. As for the code, no problem, I like a good challenge every now and again.You could probably refine that into a single regex rather than two, but my mind really was a blank yesterday.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33726-help-with-ereg-please/#findComment-158955 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.