Jump to content

[SOLVED] strpos


-entropyman

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/115997-solved-strpos/
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596391
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596400
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596403
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596406
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596419
Share on other sites

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";
?>

Link to comment
https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596438
Share on other sites

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} = " ";

Link to comment
https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596460
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/115997-solved-strpos/#findComment-596473
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.