Jump to content

Redeclare Function startelement?


wtfsmd

Recommended Posts

I have 2 function startElement() in my script is there anyway to kill the first function before it try's to re-declare the 2nd function?  ???

 

ill post my code but its pretty long.

 

<?php

// START OF CURRENT SEASON
$insideitem = false;
$tag = "";
$place = "";
$previousplace = "";
$matchesplayed = "";
$wins = "";
$losses = "";
$winpercentage = "";
$gamesfor = "";
$gamesagainst = "";
$shutouts = "";
$streak = "";
$xp = "";
$level = "";
$levelup = "";

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $place, $previousplace, $matchesplayed, $wins, $losses, $winpercentage, $gamesfor, $gamesagainst, $shutouts, $streak, $xp, $level, $levelup;
if ($insideitem) {
	$tag = $name;
} elseif ($name == "CURRENTSTATS") {
	$insideitem = true;
}
}

function endElement($parser, $name) {
global $insideitem, $tag, $place, $previousplace, $matchesplayed, $wins, $losses, $winpercentage, $gamesfor, $gamesagainst, $shutouts, $streak, $xp, $level, $levelup;
if ($name == "CURRENTSTATS") {



?>
<div class="boxOuter xl lt">
    <h3>Body Count. Stats</h3>
    <div class="boxInner" style="background:none #282828;">
        <table class="list list-center" style="border-bottom:1px solid #222;">
            <thead>
                <tr>

                    <th style="text-align:left;">Season</th>
                    <th class="stat">Place</th>
                    <th title="Matches Played" class="stat">MP</th>
                    <th title="Wins" class="stat">W</th>
                    <th title="Losses" class="stat">L</th>
                    <th title="Ties" class="stat">T</th>

                    <th title="Games For (Match Games Won)" class="stat">GF</th>
                    <th title="Games Against (Match Games Lost)" class="stat">GA</th>
                    <th title="Shutouts" class="stat">SO</th>
                    <th title="Win Percentage" class="stat">Pct</th>
                    <th title="Streak" class="stat">Strk</th>
                    <th title="Best Streak" class="stat">B.Strk</th>

                    <th title="XP / Next Level XP" class="stat">XP/LvlUp</th>
                    <th title="XP Level" class="stat" style="width:60px;">Level</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                	<td style="text-align:left;"><a href="/xbox360/call-of-duty-4/ladder/team/standings?season=448">Summer 2008</a></td>
                	<td class="alt1"><?echo $place;?><sup>rd</sup> <img src="http://static.gamebattles.com/gb/icons/misc/rank_down.png" class="icon-rank" title="Down 1 place in standings" /></td>
                	<td><?echo $matchesplayed;?></td>
                	<td class="alt1"><?echo $wins;?></td>
                	<td><?echo $losses;?></td>
                	<td class="alt1">0</td>
               		<td><?echo $gamesfor;?></td>
                	<td class="alt1"><?echo $gamesagainst;?></td>
                	<td><?echo $shutouts;?></td>
                	<td class="alt1"><?echo $winpercentage;?></td>
                	<td><?echo $streak;?></td>
                	<td class="alt1">8W</td>
                	<td><?echo $xp;?> / <?echo $levelup;?></td>
                	<td class="alt1"><div class="bar-outer" style="width:80px;"><div class="bar-inner" style="width:13%;"><div class="bar-text" style="width:80px;"><?echo $level;?></div></div></div></td>
                </tr>

                
<?

	$place = "";
	$previousplace = "";
	$matchesplayed = "";
	$wins = "";
	$losses = "";
	$winpercentage = "";
	$gamesfor = "";
	$gamesagainst = "";
	$shutouts = "";
	$streak = "";
	$xp = "";
	$level = "";
	$levelup = "";
	$insideitem = false;

}
}

function characterData($parser, $data) {
global $insideitem, $tag, $place, $previousplace, $matchesplayed, $wins, $losses, $winpercentage, $gamesfor, $gamesagainst, $shutouts, $streak, $xp, $level, $levelup;
if ($insideitem) {
switch ($tag) {
	case "PLACE":
	$place .= $data;
	break;
	case "PREVIOUSPLACE":
	$previousplace .= $data;
	break;
	case "MATCHESPLAYED":
	$matchesplayed .= $data;
	break;
	case "WINS":
	$wins .= $data;
	break;
	case "LOSSES":
	$losses .= $data;
	break;
	case "WINPERCENTAGE":
	$winpercentage .= $data;
	break;
	case "GAMESFOR":
	$gamesfor .= $data;
	break;
	case "GAMESAGAINST":
	$gamesagainst .= $data;
	break;
	case "SHUTOUTS":
	$shutouts .= $data;
	break;
	case "STREAK":
	$streak .= $data;
	break;
	case "XP":
	$xp .= $data;
	break;
	case "LEVEL":
	$level .= $data;
	break;
	case "LEVELUP":
	$levelup .= $data;
	break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://gamebattles.com/xbox360/call-of-duty-4/team/body-count-1/stats.xml","r")
or die("Error reading XML data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
	or die(sprintf("XML error: %s at line %d", 
		xml_error_string(xml_get_error_code($xml_parser)), 
		xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);
/* END OF CURRENT SEASON
------------------------
------------------------
START OF ALL TIME STATS*/
$insideitem = false;
$tag = "";
$atplace = "";
$atpreviousplace = "";
$atmatchesplayed = "";
$atwins = "";
$atlosses = "";
$atwinpercentage = "";
$atgamesfor = "";
$atgamesagainst = "";
$atshutouts = "";
$atstreak = "";
$atxp = "";
$atlevel = "";
$atlevelup = "";

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $atplace, $atpreviousplace, $atmatchesplayed, $atwins, $atlosses, $atwinpercentage, $atgamesfor, $atgamesagainst, $atshutouts, $atstreak, $atxp, $atlevel, $atlevelup;
if ($insideitem) {
	$tag = $name;
} elseif ($name == "ALLTIMESTATS") {
	$insideitem = true;
}
}

function endElement($parser, $name) {
global $insideitem, $tag, $atplace, $atpreviousplace, $atmatchesplayed, $atwins, $atlosses, $atwinpercentage, $atgamesfor, $atgamesagainst, $atshutouts, $atstreak, $atxp, $atlevel, $atlevelup;
if ($name == "ALLTIMESTATS") {
?>
<tr>
                    <td class="alt2" style="text-align:left;">All-Time</td>
                    <td>N/A</td>
                    <td class="alt2"><?echo $atmatchesplayed?></td>
                    <td><?echo $atwins?></td>
                    <td class="alt2"><?echo $atlosses?></td>

                    <td>0</td>
                    <td class="alt2"><?echo $atgamesfor?></td>
                    <td><?echo $atgamesagainst?></td>
                    <td class="alt2"><?echo $atshutouts?></td>
                    <td><?echo $atwinpercentage?></td>
                    <td class="alt2"><?echo $atstreak?></td>
                    <td>8W</td>

                    <td class="alt2"><?echo $atxp?> / <?echo $atlevelup?></td>
                    <td><div class="bar-outer" style="width:80px;"><div class="bar-inner" style="width:13%;"><div class="bar-text" style="width:80px;"><?echo $atlevelup?></div></div></div></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<?

	$atplace = "";
	$atpreviousplace = "";
	$atmatchesplayed = "";
	$atwins = "";
	$atlosses = "";
	$atwinpercentage = "";
	$atgamesfor = "";
	$atgamesagainst = "";
	$atshutouts = "";
	$atstreak = "";
	$atxp = "";
	$atlevel = "";
	$atlevelup = "";
	$insideitem = false;
}		
}

function characterData($parser, $data) {
global $insideitem, $tag, $atplace, $atpreviousplace, $atmatchesplayed, $atwins, $atlosses, $atwinpercentage, $atgamesfor, $atgamesagainst, $atshutouts, $atstreak, $atxp, $atlevel, $atlevelup;
if ($insideitem) {
switch ($tag) {
	case "PLACE":
	$atplace .= $data;
	break;
	case "PREVIOUSPLACE":
	$atpreviousplace .= $data;
	break;
	case "MATCHESPLAYED":
	$atmatchesplayed .= $data;
	break;
	case "WINS":
	$atwins .= $data;
	break;
	case "LOSSES":
	$atlosses .= $data;
	break;
	case "WINPERCENTAGE":
	$atwinpercentage .= $data;
	break;
	case "GAMESFOR":
	$atgamesfor .= $data;
	break;
	case "GAMESAGAINST":
	$atgamesagainst .= $data;
	break;
	case "SHUTOUTS":
	$atshutouts .= $data;
	break;
	case "STREAK":
	$atstreak .= $data;
	break;
	case "XP":
	$atxp .= $data;
	break;
	case "LEVEL":
	$atlevel .= $data;
	break;
	case "LEVELUP":
	$atlevelup .= $data;
	break;
}
}
}
	//End OF All Time

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://gamebattles.com/xbox360/call-of-duty-4/team/body-count-1/stats.xml","r")
or die("Error reading XML data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
	or die(sprintf("XML error: %s at line %d", 
		xml_error_string(xml_get_error_code($xml_parser)), 
		xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>

Link to comment
Share on other sites

No, you cannot create a function which has already been created. Looks to me like all you need is a little logic. Something along the lines of having the 3rd parameter as optional. If it's been set, then do the stuff that's in your second function declaration; if not's not been set, then don't.#

 

edit: e.g:

 

<?php
function myfunction ($foo,$bar=FALSE){
    //do something with $foo;
    if($bar==TRUE){
        // if $bar has been set, then do something different.
    }
}
myfunction('some value'); //only do the first part
myfunction('some value',TRUE);//also do second part
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.