Valhalla Legends Forums Archive | Web Development | [PHP] WarCraft III Stat Fetching

AuthorMessageTime
AssassinRC
This is the backend code for the Royal Council WarCraft III stat spider, although it's written specifically for {RC}, the code provides more than enough information on how to integrate something of the likes into any page. There is MySQL code written directly into this, any questions can be directed to me! Enjoy.

[code]<?
class FetchAPI
{

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Private Variables

   var $StatsHTML;
   var $StatsText;
   var $StatsArray;
   var $Realm;
   var $ID;
   
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Public Functions
   
   function Init($InputRealm,$Player,$ID)
   {
   
   if ($InputRealm == 1) {
      $Realm = "Azeroth";
      $Gametype = "w3xp";
   } elseif($InputRealm == 2) {
      $Realm = "Kalimdor";
      $Gametype = "w3xp";
   } elseif($InputRealm == 3) {
      $Realm = "Lordaeron";
      $Gametype = "w3xp";
   } elseif($InputRealm == 4) {
      $Realm = "Northrend";
      $Gametype = "w3xp";
   } else {
      $Realm = "Bad game.";
   }
   
      $BNetURL = "http://www.battle.net/war3/ladder/".$Gametype."-player-profile.aspx?Gateway=".$Realm."&PlayerName=".$Player."";
      $this->$testing = "". $BNetURL . "";
      $this->StatsHTML = implode('',file($this->$testing));
      $this->Convert();
      $this->CreateTextArray($ID);
      $this->CreateHTMLArray();
   }
   
   //Function Name: GetHTML
   //Description: Returns the complete HTML for the profile
   //Arguments: None
   //Return: string
   function GetStatsHTML()
   {
      return $this->StatsHTML;
   }
   
   //Function Name: GetStatsText
   //Description: Returns the Text of the Player, this is the HTML with the tags stripped
   //Arguments: None
   //Return: string
   function GetStatsText()
   {
      return $this->StatsText;
   }
   


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Private Functions
   
   //Dummy function for ConvertHTMLToText   
   function Convert()
   {
      $this->StatsText .= $this->ConvertHTMLToText($this->StatsHTML);
   }
   

   function CreateTextArray($ID)
   {
    $this->StatsArray = explode("\r",$this->StatsText);

      $basequery = "UPDATE RCForums_members SET";

   mysql_connect("localhost", "account", "password")
or die("Could not connect: " . mysql_error());
      
      $theLocation="" . $this->$testing . "";
      $startingpoint = "<td width=\"11\" background=\"/war3/images/ladder-revise/rankingborder-left.gif\" valign=\"bottom\"><img src=\"/war3/images/ladder-revise/rankingborder-left-bot.gif\" width=\"11\" height=\"10\"></td>";
      $endingpoint = "<td width=\"11\" background=\"/war3/images/ladder-revise/rankingborder-right.gif\" valign=\"bottom\"><img src=\"/war3/images/ladder-revise/rankingborder-right-bot.gif\" width=\"11\" height=\"10\"></td>";

      // - "Don't touch this part..."
         preg_match("/^(https?:\/\/)?([^\/]*)(.*)/i", "$theLocation", $matches);
         $theDomain = "http://" . $matches[2];
         $page = $matches[3];

                  $fd = fopen($theDomain.$page, "r"); // can change to "rb", on NT/2000 servers, if problems.
                  $value = "";
                  
                  while(!feof($fd)){
                     $value .= fread($fd, 4096);   
                  }
         
         fclose($fd);

      $start= strpos($value, "$startingpoint");
      $finish= strpos($value, "$endingpoint");
      $length= $finish-$start;
      $value=substr($value, $start, $length);
      // end "don't touch this part"

      // $value = eregi_replace( "<img src=[^>]*>", "", $value ); // Remove all image tags.
      $value = eregi_replace( "<IMG alt=[^>]*>", "", $value ); // Remove all image alt="whatever" tags
      $value = eregi_replace( "<class[^>]*>", "", $value ); // Remove all variations of <class> tags.
      $value = eregi_replace( "<table[^>]*>", "", $value ); // Remove ALL variations of <table> tags.
      $value = eregi_replace( "<tr[^>]*>", "", $value ); // Replace <tr> tags with blank space.
      $value = eregi_replace( "<td[^>]*>", "", $value ); // Remove all variations of <td> tags.
      $value = eregi_replace( "<img src=\"/war3/images/ladder-revise/rankingborder-left-bot.gif\" width=\"11\" height=\"10\">", "", $value ); // Remove garbage.
      $value = eregi_replace( "<img src=\"/war3/images/ladder-revise/rankingborder-right-bot.gif\" width=\"11\" height=\"10\">", "", $value ); // Remove garbage.
      $value = eregi_replace( "/war3/ladder/portraits/animated/war3/", "http://www.battle.net/war3/ladder/portraits/animated/war3/", $value ); // Fix war3 image paths.
      $value = eregi_replace( "/war3/ladder/portraits/animated/w3xp/", "http://www.battle.net/war3/ladder/portraits/animated/w3xp/", $value ); // Fix war3 image paths.


      // Replace ending tags.
      $value = str_replace( "</font>", "", $value ); // Remove closing </font> tags.
      $value = str_replace( "</table>", "", $value ); // Remove closing </table> tags.
      $value = str_replace( "</tr>", "", $value ); // Remove closing </tr> tags.
      $value = str_replace( "</td>", "", $value ); // Remove closing </td> tags.
      $value = str_replace( "<center>", "", $value ); // Remove <center> tag...
      $value = str_replace( "</center>", "", $value ); // ...alignment calls.
      $value = str_replace( "<b>", "", $value ); // Remove <b> tags.
      $value = str_replace( "</b>", "", $value ); // Remove closing </b> tags...

      // replace normal links with HTML to open fetched links in new window
      $value = eregi_replace( "href=", "target=\"_blank\" href=", $value );

      // open links that use " in new window
      $value = eregi_replace( "href=\"", "target=\"_blank\" href=\"", $value );
      $icon = preg_replace("/(href=\"?)(\/[^\"\/]+)/", "\\1" . $theDomain . "\\2", $value);
      
      ///////////////////////ADDITIONAL / ICON SEPERATION
      
      $theLocation2="" . $this->$testing . "";
      $startingpoint2 = "\") == -1) {";
      $endingpoint2 = "document.write(\"None\");";

      // - "Don't touch this part..."
         preg_match("/^(https?:\/\/)?([^\/]*)(.*)/i", "$theLocation2", $matches2);
         $theDomain2 = "http://" . $matches2[2];
         $page = $matches2[3];

                  $fd2 = fopen($theDomain2.$page, "r"); // can change to "rb", on NT/2000 servers, if problems.
                  $value2 = "";
                  
                  while(!feof($fd2)){
                     $value2 .= fread($fd2, 4096);   
                  }
         
         fclose($fd2);

      $start2= strpos($value2, "$startingpoint2");
      $finish2= strpos($value2, "$endingpoint2");
      $length2= $finish2-$start2;
      $value2=substr($value2, $start2, $length2);
      // end "don't touch this part"

      // Replace ending tags.
      $value2 = str_replace( ") == -1)", "", $value2 ); // Remove garbage.
      $value2 = str_replace( "} else {", "", $value2 ); // Remove garbage.
      $value2 = str_replace( "\");", "", $value2 ); // Remove garbage.
      $value2 = str_replace( "document.write(\"", "", $value2 ); // Remove garbage.
      $value2 = str_replace( "\" {", "", $value2 ); // Remove garbage.

      $additional = preg_replace("/(href=\"?)(\/[^\"\/]+)/", "\\1" . $theDomain2 . "\\2", $value2);
      $additional = html_entity_decode(htmlentities($additional, ENT_COMPAT, 'UTF-8'));
   
    if (strlen($this->StatsArray[50]) > 10) {
         $error = "<table width='95%' height='85%'>
<tr>
   <td valign='middle'>
      <table align='center' border='0' cellspacing='1' cellpadding='0'>
      <tr>
         <td bgcolor='#000000'>
            <table width='100%' border='0' cellspacing='0' cellpadding='0'>
            <tr>
             <td bgcolor='#000000' valign='bottom' width='11' height='17' align='left' bgcolor='#000000'><img src='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageHeaderLeft.gif'></td>
             <td bgcolor='#000000' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageHeader2.gif'>&nbsp;</td>
             <td bgcolor='#000000' valign='bottom' width='11' height='17' align='left' bgcolor='#000000'><img src='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageHeaderRight.gif'></td>
            </tr>
            <tr>
             <td bgcolor='#000000' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageLeft.gif'></td>
               <td class='vindversion' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageBG.jpg' width='100%' align='center'>
                     <span class='vindfaqheadsmall'>&nbsp;<br><b>&nbsp;&nbsp;&nbsp;Player Does Not Exist! </b></span>&nbsp;<br>&nbsp;
               </td>
             <td bgcolor='#000000' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageRight.gif'></td>
          </tr>
            <tr>
             <td bgcolor='#000000' valign='top' width='11' height='17' align='left' bgcolor='#000000'><img src='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageFooterLeft.gif'></td>
<td bgcolor='#000000' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageFooter.gif'>&nbsp;</td>
             <td bgcolor='#000000' valign='top width='11' height='17' align='left' bgcolor='#000000'><img src='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageFooterRight.gif'></td>
            </tr>
         </table>
         </td>
      </tr>
    </table>
   </td>
</tr>
</table>";      
         print "".$error."";
    } else {

$sologame = array_search("Solo Games",$this->StatsArray);
    if(is_null($sologame))
$sologame = false;
   
if($sologame !== false)
{
    $soloplay = "1";
          if (strlen($this->StatsArray[$sologame+2]) < 2) {
    $soloquery = " sololevel='{$this->StatsArray[$sologame+3]}', solorank = '{$this->StatsArray[$sologame+7]}', solowins='{$this->StatsArray[$sologame+9]}', sololosses='{$this->StatsArray[$sologame+11]}', soloexp='{$this->StatsArray[$sologame+6]}',";
         } else {
    $soloquery = " sololevel='{$this->StatsArray[$sologame+4]}', solorank = '{$this->StatsArray[$sologame+8]}', solowins='{$this->StatsArray[$sologame+10]}', sololosses='{$this->StatsArray[$sologame+12]}', soloexp='{$this->StatsArray[$sologame+7]}',";
         }
         
      }
      
$ffagame = array_search("FFA Games",$this->StatsArray);
    if(is_null($ffagame))
$ffagame = false;
   
if($ffagame !== false)
{
          if (strlen($this->StatsArray[$ffagame+2]) < 2) {         
    $ffaquery = " ffalevel='{$this->StatsArray[$ffagame+3]}', ffarank='{$this->StatsArray[$ffagame+7]}', ffawins='{$this->StatsArray[$ffagame+9]}', ffalosses='{$this->StatsArray[$ffagame+11]}', ffaexp='{$this->StatsArray[$sologame+6]}',";
         } else {
    $ffaquery = " ffalevel='{$this->StatsArray[$ffagame+4]}', ffarank='{$this->StatsArray[$ffagame+8]}', ffawins='{$this->StatsArray[$ffagame+10]}', ffalosses='{$this->StatsArray[$ffagame+12]}', ffaexp='{$this->StatsArray[$ffagame+7]}',";
         }      
         
      }
      
$teamgame = array_search("Team Games",$this->StatsArray);
    if(is_null($teamgame))
$teamgame = false;
   
if($teamgame !== false)
{
          if (strlen($this->StatsArray[$teamgame+2]) < 2) {         
    $teamquery = " teamlevel='{$this->StatsArray[$teamgame+3]}', teamrank='{$this->StatsArray[$teamgame+7]}', teamwins='{$this->StatsArray[$teamgame+9]}', teamlosses='{$this->StatsArray[$teamgame+11]}', teamexp='{$this->StatsArray[$teamgame+6]}',";
         } else {
          $teamquery = " teamlevel='{$this->StatsArray[$teamgame+4]}', teamrank='{$this->StatsArray[$teamgame+8]}', teamwins='{$this->StatsArray[$teamgame+10]}', teamlosses='{$this->StatsArray[$teamgame+12]}', teamexp='{$this->StatsArray[$teamgame+7]}',";
         }      
         
      }      
      
$playhistory = array_search("Play History:",$this->StatsArray);
    if(is_null($playhistory))
$retval = false;
   
if($playhistory !== false)
{
         if ($this->StatsArray[$playhistory+4] == "Random:") {
            $randomquery = " randomwins='{$this->StatsArray[$playhistory+5]}', randomlosses='{$this->StatsArray[$playhistory+6]}', randompercent='{$this->StatsArray[$playhistory+7]}',";
         }
         
         if ($this->StatsArray[$playhistory+4] == "Human:") {
            $humanquery = " humanwins='{$this->StatsArray[$playhistory+5]}', humanlosses='{$this->StatsArray[$playhistory+6]}', humanpercent='{$this->StatsArray[$playhistory+7]}',";
         }
         
         if ($this->StatsArray[$playhistory+4] == "Orc:") {
            $orcquery = " orcwins='{$this->StatsArray[$playhistory+5]}', orclosses='{$this->StatsArray[$playhistory+6]}', orcpercent='{$this->StatsArray[$playhistory+7]}',";
         }
         
         if ($this->StatsArray[$playhistory+4] == "Night Elf:") {
            $nequery = " newins='{$this->StatsArray[$playhistory+5]}', nelosses='{$this->StatsArray[$playhistory+6]}', nepercent='{$this->StatsArray[$playhistory+7]}',";
         }
         
         if ($this->StatsArray[$playhistory+4] == "Undead:") {
            $udquery = " udwins='{$this->StatsArray[$playhistory+5]}', udlosses='{$this->StatsArray[$playhistory+6]}', udpercent='{$this->StatsArray[$playhistory+7]}',";
         }
         
         if ($this->StatsArray[$playhistory+4] == "Total:") {
            $totalquery = " totalwins='{$this->StatsArray[$playhistory+5]}', totallosses='{$this->StatsArray[$playhistory+6]}', totalpercent='{$this->StatsArray[$playhistory+7]}',";
         }
         
         if ($this->StatsArray[$playhistory+8] == "Random:") {
            $randomquery = " randomwins='{$this->StatsArray[$playhistory+9]}', randomlosses='{$this->StatsArray[$playhistory+10]}', randompercent='{$this->StatsArray[$playhistory+11]}',";
         }
         
         if ($this->StatsArray[$playhistory+8] == "Human:") {
            $humanquery = " humanwins='{$this->StatsArray[$playhistory+9]}', humanlosses='{$this->StatsArray[$playhistory+10]}', humanpercent='{$this->StatsArray[$playhistory+11]}',";
         }
         
         if ($this->StatsArray[$playhistory+8] == "Orc:") {
            $orcquery = " orcwins='{$this->StatsArray[$playhistory+9]}', orclosses='{$this->StatsArray[$playhistory+10]}', orcpercent='{$this->StatsArray[$playhistory+11]}',";
         }
         
         if ($this->StatsArray[$playhistory+8] == "Night Elf:") {
            $nequery = " newins='{$this->StatsArray[$playhistory+9]}', nelosses='{$this->StatsArray[$playhistory+10]}', nepercent='{$this->StatsArray[$playhistory+11]}',";
         }
         
         if ($this->StatsArray[$playhistory+8] == "Undead:") {
            $udquery = " udwins='{$this->StatsArray[$playhistory+9]}', udlosses='{$this->StatsArray[$playhistory+10]}', udpercent='{$this->StatsArray[$playhistory+11]}',";
         }
         
         if ($this->StatsArray[$playhistory+8] == "Total:") {
            $totalquery = " totalwins='{$this->StatsArray[$playhistory+9]}', totallosses='{$this->StatsArray[$playhistory+10]}', totalpercent='{$this->StatsArray[$playhistory+11]}',";
         }   
         
         if ($this->StatsArray[$playhistory+12] == "Random:") {
            $randomquery = " randomwins='{$this->StatsArray[$playhistory+13]}', randomlosses='{$this->StatsArray[$playhistory+14]}', randompercent='{$this->StatsArray[$playhistory+15]}',";
         }
         
         if ($this->StatsArray[$playhistory+12] == "Human:") {
            $humanquery = " humanwins='{$this->StatsArray[$playhistory+13]}', humanlosses='{$this->StatsArray[$playhistory+14]}', humanpercent='{$this->StatsArray[$playhistory+15]}',";
         }
         
         if ($this->StatsArray[$playhistory+12] == "Orc:") {
            $orcquery = " orcwins='{$this->StatsArray[$playhistory+13]}', orclosses='{$this->StatsArray[$playhistory+14]}', orcpercent='{$this->StatsArray[$playhistory+15]}',";
         }
         
         if ($this->StatsArray[$playhistory+12] == "Night Elf:") {
            $nequery = " newins='{$this->StatsArray[$playhistory+13]}', nelosses='{$this->StatsArray[$playhistory+14]}', nepercent='{$this->StatsArray[$playhistory+15]}',";
         }
         
         if ($this->StatsArray[$playhistory+12] == "Undead:") {
            $udquery = " udwins='{$this->StatsArray[$playhistory+13]}', udlosses='{$this->StatsArray[$playhistory+14]}', udpercent='{$this->StatsArray[$playhistory+15]}',";
         }
         
         if ($this->StatsArray[$playhistory+12] == "Total:") {
            $totalquery = " totalwins='{$this->StatsArray[$playhistory+13]}', totallosses='{$this->StatsArray[$playhistory+14]}', totalpercent='{$this->StatsArray[$playhistory+15]}',";
         }   
         
         if ($this->StatsArray[$playhistory+16] == "Random:") {
            $randomquery = " randomwins='{$this->StatsArray[$playhistory+17]}', randomlosses='{$this->StatsArray[$playhistory+18]}', randompercent='{$this->StatsArray[$playhistory+19]}',";
         }
         
         if ($this->StatsArray[$playhistory+16] == "Human:") {
            $humanquery = " humanwins='{$this->StatsArray[$playhistory+17]}', humanlosses='{$this->StatsArray[$playhistory+18]}', humanpercent='{$this->StatsArray[$playhistory+19]}',";
         }
         
         if ($this->StatsArray[$playhistory+16] == "Orc:") {
            $orcquery = " orcwins='{$this->StatsArray[$playhistory+17]}', orclosses='{$this->StatsArray[$playhistory+18]}', orcpercent='{$this->StatsArray[$playhistory+19]}',";
         }
         
         if ($this->StatsArray[$playhistory+16] == "Night Elf:") {
            $nequery = " newins='{$this->StatsArray[$playhistory+17]}', nelosses='{$this->StatsArray[$playhistory+18]}', nepercent='{$this->StatsArray[$playhistory+19]}',";
         }
         
         if ($this->StatsArray[$playhistory+16] == "Undead:") {
            $udquery = " udwins='{$this->StatsArray[$playhistory+17]}', udlosses='{$this->StatsArray[$playhistory+18]}', udpercent='{$this->StatsArray[$playhistory+19]}',";
         }
         
         if ($this->StatsArray[$playhistory+16] == "Total:") {
            $totalquery = " totalwins='{$this->StatsArray[$playhistory+17]}', totallosses='{$this->StatsArray[$playhistory+18]}', totalpercent='{$this->StatsArray[$playhistory+19]}',";
         }   
         
         if ($this->StatsArray[$playhistory+20] == "Random:") {
            $randomquery = " randomwins='{$this->StatsArray[$playhistory+21]}', randomlosses='{$this->StatsArray[$playhistory+22]}', randompercent='{$this->StatsArray[$playhistory+23]}',";
         }
         
         if ($this->StatsArray[$playhistory+20] == "Human:") {
            $humanquery = " humanwins='{$this->StatsArray[$playhistory+21]}', humanlosses='{$this->StatsArray[$playhistory+22]}', humanpercent='{$this->StatsArray[$playhistory+23]}',";
         }
         
         if ($this->StatsArray[$playhistory+20] == "Orc:") {
            $orcquery = " orcwins='{$this->StatsArray[$playhistory+21]}', orclosses='{$this->StatsArray[$playhistory+22]}', orcpercent='{$this->StatsArray[$playhistory+23]}',";
         }
         
         if ($this->StatsArray[$playhistory+20] == "Night Elf:") {
            $nequery = " newins='{$this->StatsArray[$playhistory+21]}', nelosses='{$this->StatsArray[$playhistory+22]}', nepercent='{$this->StatsArray[$playhistory+23]}',";
         }
         
         if ($this->StatsArray[$playhistory+20] == "Undead:") {
            $udquery = " udwins='{$this->StatsArray[$playhistory+21]}', udlosses='{$this->StatsArray[$playhistory+22]}', udpercent='{$this->StatsArray[$playhistory+23]}',";
         }
         
         if ($this->StatsArray[$playhistory+20] == "Total:") {
            $totalquery = " totalwins='{$this->StatsArray[$playhistory+21]}', totallosses='{$this->StatsArray[$playhistory+22]}', totalpercent='{$this->StatsArray[$playhistory+23]}',";
         }
         
         if ($this->StatsArray[$playhistory+24] == "Total:") {
            $totalquery = " totalwins='{$this->StatsArray[$playhistory+25]}', totallosses='{$this->StatsArray[$playhistory+26]}', totalpercent='{$this->StatsArray[$playhistory+27]}',";
         }
         
$lastladder = array_search("Last Ladder Game:",$this->StatsArray);
    if(is_null($lastladder))
$retval = false;
   
    if ($this->StatsArray[29] == "<!--This link is neither endorsed nor supported by Blizzard ") {
          $profile = "";
    } else {
          $profile = $this->StatsArray[29];
    }
   
if($lastladder !== false)
{
          $ladder = $this->StatsArray[$lastladder+1];
    }
            
         $time = date("Y-m-d", mktime(0,0,0, date(m), date(d),date(Y)));
         $endquery = " profile='".$profile."', lastladder='".$ladder."', additionalinfo='".$additional."', icon='".$icon."', last_update='".$time."', rpg_hp='100' WHERE id=$ID";
         $query = "".$basequery."".$soloquery."".$ffaquery."".$teamquery."".$randomquery."".$humanquery."".$orcquery."".$nequery."".$udquery."".$totalquery."".$endquery."";
         mysql_query("".$query."");
         
         $error = "<table width='95%' height='85%'>
<tr>
   <td valign='middle'>
      <table align='center' border='0' cellspacing='1' cellpadding='0'>
      <tr>
         <td bgcolor='#000000'>
            <table width='100%' border='0' cellspacing='0' cellpadding='0'>
            <tr>
             <td bgcolor='#000000' valign='bottom' width='11' height='17' align='left' bgcolor='#000000'><img src='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageHeaderLeft.gif'></td>
             <td bgcolor='#000000' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageHeader2.gif'>&nbsp;</td>
             <td bgcolor='#000000' valign='bottom' width='11' height='17' align='left' bgcolor='#000000'><img src='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageHeaderRight.gif'></td>
            </tr>
            <tr>
             <td bgcolor='#000000' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageLeft.gif'></td>
               <td class='vindversion' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageBG.jpg' width='100%' align='center'>
                     <span class='vindfaqheadsmall'>&nbsp;<br><b>&nbsp;&nbsp;&nbsp;Stats Successfully Fetched -- Reload Profile! </b></span>&nbsp;<br>&nbsp;
               </td>
             <td bgcolor='#000000' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageRight.gif'></td>
          </tr>
            <tr>
             <td bgcolor='#000000' valign='top' width='11' height='17' align='left' bgcolor='#000000'><img src='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageFooterLeft.gif'></td>
<td bgcolor='#000000' background='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageFooter.gif'>&nbsp;</td>
             <td bgcolor='#000000' valign='top width='11' height='17' align='left' bgcolor='#000000'><img src='http://www.websitehostingspace.com/~assassin/Images/Forum-MessageFooterRight.gif'></td>
            </tr>
         </table>
         </td>
      </tr>
    </table>
   </td>
</tr>
</table>";      
         print "".$error."";
}
         
    } //End the Player Not Found / else / crap.
      
   }
      
   
   function CreateHTMLArray()
   {
      $this->StatsArray2 = explode("\r",$this->StatsHTML);
   }
   
   //Convert the stat HTML to Text
   function ConvertHTMLToText($document)
   {
      // $document should contain an HTML document.
      // This will remove HTML tags, javascript sections
      // and white space. It will also convert some
      // common HTML entities to their text equivalent.
      
      $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
                   "'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
                   "'([\r\n])[\s]+'", // Strip out white space
                   "'&(quot|#34);'i", // Replace html entities
                   "'&(amp|#38);'i",
                   "'&(lt|#60);'i",
                   "'&(gt|#62);'i",
                   "'&(nbsp|#160);'i",
                   "'&(iexcl|#161);'i",
                   "'&(cent|#162);'i",
                   "'&(pound|#163);'i",
                   "'&(copy|#169);'i",
                   "'&#(\d+);'e"); // evaluate as php
      
      $replace = array ("",
                   "",
                   "\\1",
                   "\"",
                   "&",
                   "<",
                   ">",
                   " ",
                   chr(161),
                   chr(162),
                   chr(163),
                   chr(169),
                   "chr(\\1)");            
                  
      return preg_replace ($search, $replace, $document);
   }

}

?>[/code]
November 28, 2003, 7:51 PM
Arta
[code]
return trim(trim(trim(trim(trim($Value)))));
[/code]

Youwhatnow?

trim() removes all leading & trailing whitespace. Trimming it 5 times won't make any difference - at least, not in any semirecent version of PHP. Is yours really old or something?
November 28, 2003, 9:24 PM
AssassinRC
Hehe, I coded it a long time ago so chances are pieces of it are outdated. I've updated it to work with every version of the battle.net stats page -- but I never bothered to update the HTML to text to Array code. I'll look into it! ;)

[EDIT] -- It looks as if I did update the code so that it wouldn't require the trim command at all in one of the versions and I just didn't remove the trim (let alone multiple trim) code. [/EDIT]
November 28, 2003, 9:30 PM
St0rm.iD
That's a very nice code contribution. +1.
November 29, 2003, 3:00 AM

Search