-entropyman Posted July 22, 2008 Share Posted July 22, 2008 Hello, hopefully you guys can help. i'm using strpos to determine whether or not a string is contained in another string. if it is, i want the line with it in it to become $final_result, if not i wanna repeati have this <?php $pos = strpos($final1, $gs); if ($pos === true) { $final1 = $final_result; } elseif ($pos = strpos($final2, $gs)) if ($pos === true) { $final2 = $final_result; } elseif ($pos = strpos($final3, $gs)) if ($pos === true) { $final3 = $final_result; } elseif ($pos = strpos($final4, $gs)) if ($pos === true) { $final4 = $final_result; } elseif ($pos = strpos($final5, $gs)) if ($pos === true) { $final5 = $final_result; } else { echo "File too Large!"; } ?> $gs = name being searched for $final# = line i always get "File too Large! any ideas why and how i can fix this? ??? thanks Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/ Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 i think the logic your looking for is like so <?php if(strpos($final1, $gs) === true) { $final1 = $final_result; }elseif($pos = strpos($final2, $gs) === true){ $final2 = $final_result; }elseif($pos = strpos($final3, $gs) === true){ $final3 = $final_result; }elseif($pos = strpos($final4, $gs) === true){ $final4 = $final_result; }elseif($pos = strpos($final5, $gs) === true){ $final5 = $final_result; }else{ echo "File too Large!"; } ?> yet i'm sure theirs better ways of doing it using an array for one (depends how your getting the info) Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596391 Share on other sites More sharing options...
unkwntech Posted July 22, 2008 Share Posted July 22, 2008 Could you please post the rest of the script and maybe and example of input data, and your expected output from that data. Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596392 Share on other sites More sharing options...
-entropyman Posted July 22, 2008 Author Share Posted July 22, 2008 nope still getting "File too Large!" lets see what else i can add $server = $_POST['serverName']; // just a giant txt file separated via returns $image = $_POST['imageName']; $number = basename($image, ".png"); $ns = file_get_contents($server); $data_array = explode("\n", $ns); $result_array = array(); $count = 0; foreach ($data_array as $value) { if (strstr($value, $number)) { $result_array[] .= $value; $count++; } } if ($count == 0) { print "Failed to find anything!"; $final_result = "NOTHING FOUND!"; } if ($count != 0) { $final1 = $result_array[0]; $final2 = $result_array[1]; $final3 = $result_array[2]; $final4 = $result_array[3]; $final5 = $result_array[4]; } $gs = 'Bill'; if(strpos($final1, $gs) === true) { $final1 = $final_result; }elseif($pos = strpos($final2, $gs) === true){ $final2 = $final_result; }elseif($pos = strpos($final3, $gs) === true){ $final3 = $final_result; }elseif($pos = strpos($final4, $gs) === true){ $final4 = $final_result; }elseif($pos = strpos($final5, $gs) === true){ $final5 = $final_result; }else{ echo "File too Large!"; } echo "$final_result"; thats a briefer version of the code, not everything, hopefully this helps Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596400 Share on other sites More sharing options...
unkwntech Posted July 22, 2008 Share Posted July 22, 2008 $final1 = $result_array[0]; $final2 = $result_array[1]; $final3 = $result_array[2]; $final4 = $result_array[3]; $final5 = $result_array[4]; Are you sure that one of these contains $gs. Try doing this $final1 = $result_array[0]; $final2 = $result_array[1]; $final3 = $gs; $final4 = $result_array[3]; $final5 = $result_array[4]; And see if it works, if it does then either $gs is not contained in the $result_array or it is not exactly matching $gs in which case you might want to turn to regex. Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596403 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 oops update to <?php if(strpos($final1, $gs) === true) { $final1 = $final_result; }elseif(strpos($final2, $gs) === true){ $final2 = $final_result; }elseif(strpos($final3, $gs) === true){ $final3 = $final_result; }elseif(strpos($final4, $gs) === true){ $final4 = $final_result; }elseif(strpos($final5, $gs) === true){ $final5 = $final_result; }else{ echo "File too Large!"; echo "'$final1'<br>'$final2'<br>'$final3'<br>'$final4'<br>'$final5'<br>"; //Debug } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596406 Share on other sites More sharing options...
-entropyman Posted July 22, 2008 Author Share Posted July 22, 2008 final1 works but it isn't set to $final_result Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596413 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 it wouldn't.. Okay this is what you want then (makes a little more sense now) set $final_result to the line containing the found string <?php if(strpos($final1, $gs) === true) { $final_result= $final1; }elseif(strpos($final2, $gs) === true){ $final_result= $final2; }elseif(strpos($final3, $gs) === true){ $final_result= $final3; }elseif(strpos($final4, $gs) === true){ $final_result= $final4; }elseif(strpos($final5, $gs) === true){ $final_result= $final5; }else{ echo "File too Large!"; echo "'$final1'<br>'$final2'<br>'$final3'<br>'$final4'<br>'$final5'<br>"; //Debug } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596419 Share on other sites More sharing options...
-entropyman Posted July 22, 2008 Author Share Posted July 22, 2008 Now it is returning "File too Large". However, final1 prints out the correct info still. Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596426 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 can you attach a file, and explain what your expecting to see Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596430 Share on other sites More sharing options...
-entropyman Posted July 22, 2008 Author Share Posted July 22, 2008 here ya go, if it works everything will be filled in its a mess i know, i'm still a noob [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596434 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 try this <?php $gs = 'Bill'; if(strpos($final1, $gs) !== false) { $final_result = $final1; }elseif(strpos($final2, $gs) !== false){ $final_result = $final2; }elseif(strpos($final3, $gs) !== false){ $final_result = $final3; }elseif(strpos($final4, $gs) !== false){ $final_result = $final4; }elseif(strpos($final5, $gs) !== false){ $final_result = $final5; }else{ echo "File too Large!"; } echo "$final_result"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596438 Share on other sites More sharing options...
-entropyman Posted July 22, 2008 Author Share Posted July 22, 2008 file too large thank you for all your help btw mate Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596443 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 i'll need the file the can you create grab a small chunk of the file i can use (the large file ) Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596447 Share on other sites More sharing options...
-entropyman Posted July 22, 2008 Author Share Posted July 22, 2008 i'll need the file the can you create grab a small chunk of the file i can use (the large file ) not to sure what ya mean but the large file is available via web the location is listed under $server Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596451 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 Heres the problem <?php $filestring = file_get_contents($image); $firstWordg = " *"; $lastWordg = "* "; $str = $filestring; $str = substr($str, strpos($str,$firstWordg)+strlen($firstWordg),strpos($str,$lastWordg)-strlen($lastWordg)); $guid_shot = stristr($str, '*'); $guid_shot{strlen($guid)-1} = " "; $guid_shot{0} = " "; $shot_guid = (explode("*", $guid_shot)); $gs = $shot_guid[0]; // end guid from shot // start htm check echo "\$gs = $gs"; //I added this it return $gs = Array ?> what are you trying to do here ? Also note that $guid was not set before this line! $guid_shot{strlen($guid)-1} = " "; Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596460 Share on other sites More sharing options...
-entropyman Posted July 22, 2008 Author Share Posted July 22, 2008 that code takes a number from the image and stores it in a variable. that is also what is displayed in the string i want to return Also note that $guid was not set before this line! $guid_shot{strlen($guid)-1} = " "; bah sorry that should be $guid_shot Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596466 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 so <p> <img src=pb001251.png> should return $gs = "001251"; or $gs = 1251; Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596469 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 try this <html><head></head><body> <?php $image = 'http://12.180.48.34/pb001251.htm'; $server = 'http://12.180.48.34/pbsvss.htm'; $number = basename($image, ".png"); $ns = file_get_contents($server); $data_array = explode("\n", $ns); $result_array = array(); $count = 0; foreach ($data_array as $value) { if (strstr($value, $number)) { $result_array[] .= $value; $count++; } } if ($count == 0) { print "Failed to find shot!"; $final_result = "NOTHING FOUND!"; } if ($count != 0) { $final1 = $result_array[0]; $final2 = $result_array[1]; $final3 = $result_array[2]; $final4 = $result_array[3]; $final5 = $result_array[4]; } // start guid from shot $filestring = file_get_contents($image); /* //Removed $firstWordg = " *"; $lastWordg = "* "; $str = $filestring; $str = substr($str, strpos($str,$firstWordg)+strlen($firstWordg),strpos($str,$lastWordg)-strlen($lastWordg)); $guid_shot = stristr($str, '*'); $guid_shot{strlen($guid)-1} = " "; $guid_shot{0} = " "; $shot_guid = (explode("*", $guid_shot)); $gs = $shot_guid[0]; #$gs="001251"; */ if (preg_match('/src=([^.\s>]*)/si', $filestring, $regs)) { $gs = $regs[1]; } // end guid from shot // start htm check #echo "\$gs = $gs"; if(strpos($final1, $gs) !== false) { $final_result = $final1; }elseif(strpos($final2, $gs) !== false){ $final_result = $final2; }elseif(strpos($final3, $gs) !== false){ $final_result = $final3; }elseif(strpos($final4, $gs) !== false){ $final_result = $final4; }elseif(strpos($final5, $gs) !== false){ $final_result = $final5; }else{ echo "File too Large!"; } //Debug echo "'$final1'<br>'$final2'<br>'$final3'<br>'$final4'<br>'$final5'<br>"; // end htm check $fragments = (explode(" ",$final_result)); $name = $fragments[4]; $time1 = $fragments[7]; $time2 = $fragments[8]; $firstWord = "="; $lastWords = "("; $guid = $fragments[6]; $firstWord = "GUID="; $lastWord = "(W)"; $guid = substr($guid, strpos($guid,$firstWord)+strlen($firstWord),strpos($guid,$lastWord)-strlen($lastWord)); if ($irregular =='0') { $server = 'Unable to calculate'; }else{ $host =(parse_url($image)); $server = $host[host]; } $hash = md5_file($image); echo "<b>Name</b>: $name <br><br><b>Name</b>: $name <br><b>GUID</b>: $guid<br><b>Player IP</b>: ???<br><b>Server IP</b>: $server<br><b>Shot Name</b>: $number<br><img src='$image'</a><br><b>Image MD5</b>: $hash<br><br><b>Banline:</b><br>$time1 $time2 $guid $name \"0.0.0.0\" PBSS-BOT<br>"; echo "<br><br><br>Code To Copy and Paste<br><br><hr>[fieldset=Manual Submission Bot][color=green][b]Player Name[/b]: {$name}[/color]<br>[color=green][b]GUID[/b]: {$guid}[/color]<br>[color=orange][b]Player IP[/b]: ???[/color]<br>[color=orange][b]Server IP[/b]: {$server}[/color]<br>[color=blue][b]Shot Name[/b]: {$number}[/color]<br>[color=blue][b]Image MD5[/b]: {$hash}[/color]<br>[fieldset=Banline]{$time1} {$time2} {$guid} {$name} \"0.0.0.0\" PBSS-BOT[/fieldset]<br>[zoom]{$image}[/zoom]<br>HTM Line:[code]{$final_result} <br>[/fieldset]<br><hr>"; ?> </body></html> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596473 Share on other sites More sharing options...
-entropyman Posted July 22, 2008 Author Share Posted July 22, 2008 thank you mate! Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596481 Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 i'm pleased this one is solved lol Quote Link to comment https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596486 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.