Frode789 Posted May 15, 2010 Share Posted May 15, 2010 Hi. I'm kind of new to PHP (HTML\CSS all the way), but I ended up testing this neat script, but I keep getting a error. Look here: http://wrath-legion.com/Roster/roster.php Overview works fine, but when I click the names I just get the warning "NO greens", and: Warning: strpos() [function.strpos]: Offset not contained in string in /roster/profile.php on line 88. Here is the relevant php file: <?php $fetch_method = 1; // 0 = file_get_contents; 1 = cURL (default) function aionarmory_fetch($url, $use_curl) { if ($use_curl) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); return $result; } else { return file_get_contents($url); } } function aionarmory_getIdFromName($type, $name) { $rname = urlencode($name); $rname = str_replace('%26quot%3B','%22', $rname); $rname = str_replace('%26%23039%3B', '%27', $rname); $rname = str_replace('+','%20', $rname); $id = aionarmory_fetch("http://www.aionarmory.com/ajaxIDLookup.aspx?type=".$type."&name=".$rname, $fetch_method); if ($id) { $rarity = 0; $icon = 0; $result = aionarmory_fetch("http://www.aionarmory.com/ExTooltips.aspx?type=".$type."&id=".$id, $fetch_method); if ($result) { $result = preg_replace('/[^A-Z0-9\{\}\[\]\<\>\(\)\.\"\'\/\-\+\$\^\*&:_,=;%!@# ]/i', '', $result); preg_match('/,rarity:([0-9]+?),/i', $result, $rarity); $rarity = $rarity[1]; preg_match('/,icon:([0-9]+?)[\}|,]/i', $result, $icon); $icon = $icon[1]; } } else { return 0; } return $id; } $page = aionarmory_fetch("http://uk.aiononline.com/livestatus/character-legion/search?serverID=33&charID=".$charID, $fetch_method); $b = substr($page, strpos($page, 'char_detail') - 12); $c = substr($b, 0, strpos($b, '<div class="notice">') - 1); $d = str_replace("3D Character", "Stats", $c); $stats = substr($d, strpos($d, '<h2>Stats</h2>') - 1); $bottom = substr($d, 0, strpos($d, '<div class="box3d_bottom">') + 400); $bottom2 = substr($bottom, 0, strpos($bottom, '<ul class="item_list" id="item">') + 0); $expression = "<div class=\"box3d_bottom\">"; $e = str_replace($expression,$expression.$stats,$bottom2); $offset = 0; $CharIDCounter = 0; if(strpos($e, "<span class=\"green\">") == 0){ $CharIDCounter++; echo "<br />NO Greens"; } while($offset = strpos($e, "<span class=\"green\">", $offset + 20)){ $CharIDCounter++; $f1 = substr($e, $offset, 100); $d1 = str_replace("<span class=\"green\">", "", $f1); $d2 = substr($d1, 0, strpos($d1, '</span>') - 1); $d3 = trim($d2); $itemarray[$CharIDCounter] = $d3; $itemarray2[$CharIDCounter] = aionarmory_getIdFromName(1, $d3); } // echo "<br />"; // Print_r ($itemarray); // echo "<br />"; // echo "<br />"; //Print_r ($itemarray2); print $e; //$test = aionarmory_getIdFromName(1, "Guardian Squad Leader s Chain Boots"); //print "<a class=\"aiondb-item-text\" href=\"http://www.aionarmory.com/item.aspx?id=".$test."\">Unknown Item</a>"; ?> Any help is appreciated, thanks! Link to comment https://forums.phpfreaks.com/topic/201835-php-error/ Share on other sites More sharing options...
Frode789 Posted May 15, 2010 Author Share Posted May 15, 2010 BUMP. Link to comment https://forums.phpfreaks.com/topic/201835-php-error/#findComment-1058733 Share on other sites More sharing options...
kenrbnsn Posted May 15, 2010 Share Posted May 15, 2010 In the user comments for the function strpos you can find: This functions throws an "Offset not contained in string" error if the offset is not in between 0 and the length of string. Since there is no line 88 in the code you posted, I'm guessing that this is the segment that's throwing the warning: <?php $e = str_replace($expression,$expression.$stats,$bottom2); $offset = 0; $CharIDCounter = 0; if(strpos($e, "<span class=\"green\">") == 0){ $CharIDCounter++; echo "<br />NO Greens"; } while($offset = strpos($e, "<span class=\"green\">", $offset + 20)){ $CharIDCounter++; $f1 = substr($e, $offset, 100); $d1 = str_replace("<span class=\"green\">", "", $f1); $d2 = substr($d1, 0, strpos($d1, '</span>') - 1); $d3 = trim($d2); $itemarray[$CharIDCounter] = $d3; $itemarray2[$CharIDCounter] = aionarmory_getIdFromName(1, $d3); } ?> At some point "$offset + 20" is becoming larger that the length of the string in "$e". Ken Link to comment https://forums.phpfreaks.com/topic/201835-php-error/#findComment-1058755 Share on other sites More sharing options...
Frode789 Posted May 15, 2010 Author Share Posted May 15, 2010 Ah, sorry. Yes, it is. Line 88: while($offset = strpos($e, "<span class=\"green\">", $offset + 20)) Hmm, okay. Link to comment https://forums.phpfreaks.com/topic/201835-php-error/#findComment-1058915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.