Topic: PHP help (str_replace isn't working)

For some reason, str_replace isn't working.  The following is the file that I need the help with:

<?php
error_reporting(E_ERROR | E_PARSE);
require("./settings.php");
require_once("languages.php");
require("styles.php");
var_dump($start_language);
var_dump($end_language);
function Color_Bind($ShipName,$Amount,$D1)
{
    global $color;
    $bound="[color=".$color[$ShipName]."]".$ShipName.$D1.$Amount."[".'/'."color]";
    return $bound;
}
function Merge($ShipArray,$AmountArray,$D1,$D2)
{
    foreach($ShipArray as $field=>$value)
    {
        $value=trim($value);
        $value=ereg_replace('   ','',$value);
        $value=trim($value);
        $AmountArray[$field]=trim($AmountArray[$field]);
        $AmountArray[$field]=ereg_replace(' ','',$AmountArray[$field]);
        $AmountArray[$field]=str_replace('.','',$AmountArray[$field]);
        $AmountArray[$field]=trim($AmountArray[$field]);
        $ShipAmount[$value]=$AmountArray[$field];
    }
    foreach($ShipAmount as $Ship=>$Amount)
    {
        $ShipAndAmount[]=Color_Bind($Ship,$Amount,$D1);
    }
    $timesThrough=0;
    $sizeDown1=sizeof($ShipAndAmount)-1;
    foreach($ShipAndAmount as $key=>$value)
    {
        if($timesThrough==$sizeDown1)
        {
            unset($ShipAndAmount[$key]);
        }
        else
        {
            $timesThrough++;
        }
    }
    $RoundPart=implode($D2,$ShipAndAmount);
    return $RoundPart;
}
function number_clean($number_string)
{
    if(is_array($number_string))
    {
        foreach($number_string as $field=>$number)
        {
            $number_string[$field]=ereg_replace("   ","",$number_string[$field]);
            $number_string[$field]=trim($number_string[$field]);
            $number_string[$field]=str_replace(".","",$number_string[$field]);
        }
    }
    else
    {
        $number_string=ereg_replace("   ","",$number_string);
        $number_string=trim($number_string);
        $number_string=str_replace(".","",$number_string);
    }
    return $number_string;
}
function number_reformat($number)
{
    if(is_array($number))
    {
        foreach($number as $field=>$number)
        {
            $number_array=str_split($number);
            foreach($number_array as $key=>$digit)
            {
                $mod_test_1=sizeof($number_array) % 3;
                $new_numb_key=sizeof($number_array)-$key;
                $test_mod=$new_numb_key % 3;
                if($test_mod == 0 && $new_numb_key<>sizeof($number_array))
                {
                    $new_numb[$new_numb_key]=".".$digit;
                }
                else
                {
                    $new_numb[$new_numb_key]=$digit;
                }
        }
        $number=implode("",$new_numb);
        }
    }
    else
    {
        $number_array=str_split($number);
        foreach($number_array as $key=>$digit)
        {
            $mod_test_1=sizeof($number_array) % 3;
                $new_numb_key=sizeof($number_array)-$key;
                $test_mod=$new_numb_key % 3;
                if($test_mod == 0 && $new_numb_key<>sizeof($number_array))
                {
                    $new_numb[$new_numb_key]=".".$digit;
                }
                else
                {
                    $new_numb[$new_numb_key]=$digit;
                }
        }
        $number=implode("",$new_numb);
    }
    return $number;
}
function word_clean($string)
{
    if(is_array($string))
    {
        foreach($string as $field=>$string)
        {
            $string[$field]=str_replace("   ","",$string[$field]);
            $string[$field]=trim($string[$field]);
        }
    }
    else
    {
        $string=str_replace("   ","",$string);
        $string=trim($string);
    }
    return $string;
}
function StealthMergeDefend($ShipArray,$BeforeArray,$AfterArray,$D1,$BtoAseperator,$D2,$Headers=TRUE)
{
    if($Headers)
    {
        global $end_language;
        $HeaderHide=$end_language['type'];
        $Header[]=$end_language['number_before'];
        $Header[]=$end_language['number_after'];
        $Headers=implode($BtoAseperator,$Header);
        $HeadersTrue[]=$HeaderHide;
        $HeadersTrue[]=$Headers;
        $All[]=implode($D1,$HeadersTrue);
    }
    if(sizeof($ShipArray)==sizeof($BeforeArray) and sizeof($BeforeArray)==sizeof($AfterArray))
    {
        foreach($ShipArray as $field=>$ShipName)
        {
            $Before[$ShipName]=$BeforeArray[$field];
            $After[$ShipName]=$AfterArray[$field];
        }
        foreach ($Before as $Ship=>$Amount)
        {
            global $color;
            $Merge[]="[color=".$color[$Ship]."]";
            $Merge[]=$Ship;
            $Merge[]=$Amount;
            $NameandBefore[$Ship]=implode($D1,$Merge);
            unset($Merge);
        }
        foreach($After as $Ship=>$Amount)
        {
            $Merge[]=$NameandBefore[$Ship];
            $Merge[]=$Amount."[/color]";
            $All[]=implode($BtoAseperator,$Merge);
            unset($Merge);
        }
        $StealthRound=implode($D2,$All);
        return $StealthRound;
    }
    else
    return;
}
$DATA=$battle;
/* Replace spaces in ship names with underscores */
$DATA=str_replace($start_language['spy_probe'],"Spy_probe",$DATA);
$DATA=str_replace($start_language['small_fighter'],"Small_fighter",$DATA);
$DATA=str_replace($start_language['small_trans'],"Small_transport",$DATA);
$DATA=str_replace($start_language['large_trans'],"Large_transport",$DATA);
$DATA=str_replace($start_language['colony_ship'],"Colony_ship",$DATA);
$DATA=str_replace($start_language['solar_cell'],"Solar_cell",$DATA);
$DATA=str_replace($start_language['stealth_bomber'],"Stealth_bomber",$DATA);
$DATA=str_replace($start_language['isb'],"Imperial_starbase",$DATA);
$DATA=str_replace($start_language['lgc'],"Light_graviton_cannon",$DATA);
$DATA=str_replace($start_language['hgc'],"Heavy_graviton_cannon",$DATA);
$DATA=str_replace($start_language['hgc'],"Ion_cannon",$DATA);
$DATA=str_replace($start_language['positron'],"Positron_lighter",$DATA);
$DATA=str_replace($start_language['ivc'],"Interval_cannon",$DATA);
$DATA=str_replace($start_language['lcb'],"Laser_cannon_battery",$DATA);
$DATA=str_replace($start_language['sc'],"Solar_cannon",$DATA);
$DATA=str_replace($start_language['ssd'],"Small_shield_dome",$DATA);
$DATA=str_replace($start_language['lsd'],"Large_shield_dome",$DATA);
$DATA=preg_replace("/\n/"," ",$DATA);
$DATA=split($start_language['StartSentence']." ",$DATA,2);
$DATA=split(" :",$DATA[1],2);
$DateTime=$DATA[0];
$DATA=spliti($start_language['round']." - 1 -",$DATA[1],2);
$Stealth=$DATA[0];
/* Stealth Section */
$Stealth=split($start_language['Defender'],$Stealth,2);
$StealthRound["SBAmt_Attack"]=split($start_language['number'],$Stealth[0],2);
$StealthRound["SBAmt_Attack"]=number_clean($StealthRound["SBAmt_Attack"]);
$StealthRound["SBAmt_Attack"]=$StealthRound["SBAmt_Attack"][1];
$Stealth=split($start_language['type'],$Stealth[1],2);
$Stealth=split($start_language['number_before'],$Stealth[1],2);
$StealthRound["Defend_Item_Name"]=word_clean($Stealth[0]);
$Stealth=split($start_language['number_after'],$Stealth[1],2);
$StealthRound["Defend_Item_Before"]=number_clean($Stealth[0]);
$Stealth=split($start_language['stealth_start'],$Stealth[1],2);
$StealthRound["Defend_Item_After"]=number_clean($Stealth[0]);
$Stealth=split($start_language['stealth_end'],$Stealth[1],2);
$StealthRound["Destroyed_Items"]=number_clean($Stealth[0]);
$StealthRound["Defend_Item_Name"]=split(" ",$StealthRound["Defend_Item_Name"]);
$StealthRound["Defend_Item_Before"]=split(" ",$StealthRound["Defend_Item_Before"]);
$StealthRound["Defend_Item_After"]=split(" ",$StealthRound["Defend_Item_After"]);
$ShipsPlusAmt["Stealth"]["Bomber"]="[color=".$color['Stealth_bomber']."]Stealth_bomber".$style['ShipName-Number-Seperator'].$StealthRound["SBAmt_Attack"]."[/color]";
$ShipsPlusAmt["Stealth"]["Defense"]=StealthMergeDefend($StealthRound["Defend_Item_Name"],$StealthRound["Defend_Item_Before"],$StealthRound["Defend_Item_After"]," ","-->","\n");
/* Round 1 */
$DATA=spliti($start_language['round']." - 2 -",$DATA[1],2);
$Round1=$DATA[0];
$Round1=split($start_language['Attacker'],$Round1,2);
$Round1=split($start_language['Defender'],$Round1[1],2);
$Attack=$Round1[0];
$Attack=split("\[",$Attack,2);
$Attacker=trim($Attack[0]);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[1]['Attack']=Merge($Ships,$ShipAmt,"-->","\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round1[1];
$Defend=split("\[",$Defend,2);
$Defender=trim($Defend[0]);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language['round'],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[1]['Defend']=Merge($Ships,$ShipAmt,"-->","\n");
unset($ShipAmt,$Ships,$ShipsAmt);
unset($Attack,$Defend);
/* Round 2 */
$DATA=spliti($start_language['round']." - 3 -",$DATA[1],2);
$Round2=$DATA[0];
$Round2=split($start_language['Attacker'],$Round2,2);
$Round2=split($start_language['Defender'],$Round2[1],2);
$Attack=$Round2[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[2]['Attack']=Merge($Ships,$ShipAmt,"-->","\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round2[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language['round'],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[2]['Defend']=Merge($Ships,$ShipAmt,"-->","\n");
unset($Attack,$Defend);
/* Round 3 */
$DATA=spliti($start_language['round']." - 4 -",$DATA[1],2);
$Round3=$DATA[0];
$Round3=split($start_language['Attacker'],$Round3,2);
$Round3=split($start_language["Defender"],$Round3[1],2);
$Attack=$Round3[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[3]['Attack']=Merge($Ships,$ShipAmt,"-->","\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round3[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language['round'],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[3]['Defend']=Merge($Ships,$ShipAmt,"-->","\n");
unset($Attack,$Defend);
/* Round 4 */
$DATA=spliti($start_language['round']." - 5 -",$DATA[1],2);
$Round4=$DATA[0];
$Round4=split($start_language["Attacker"],$Round4,2);
$Round4=split($start_language["Defender"],$Round4[1],2);
$Attack=$Round4[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[4]['Attack']=Merge($Ships,$ShipAmt,"-->","\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round4[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language["round"],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[4]['Defend']=Merge($Ships,$ShipAmt,"-->","\n");
/* Round 5 */
$DATA=spliti($start_language['round']." - 6 -",$DATA[1],2);
$Round5=$DATA[0];
$Round5=split($start_language["Attacker"],$Round5,2);
$Round5=split($start_language["Defender"],$Round5[1],2);
$Attack=$Round5[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[5]['Attack']=Merge($Ships,$ShipAmt,"-->","\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round5[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language["round"],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[5]['Defend']=Merge($Ships,$ShipAmt,"-->","\n");
/* Round 6 */
$Round6=$DATA[1];
$Round6=split($start_language["Attacker"],$Round5,2);
$Round6=split($start_language["Defender"],$Round5[1],2);
$Attack=$Round6[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[6]['Attack']=Merge($Ships,$ShipAmt,"-->","\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round6[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language["round"],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[6]['Defend']=Merge($Ships,$ShipAmt,"-->","\n");
/* Figure out Last Round and switch ship names back */
function ShipUpdate(&$ShipsPlusAmt,$end_language){
$RoundNumb=1;
extract($end_language);
foreach($ShipsPlusAmt as $Round)
{
    foreach($Round as $Part=>$ShipString)
    {
        $ShipString=str_replace("Spy_probe",$spy_probe,$ShipString);
        $ShipString=str_replace("Small_fighter",$small_fighter,$ShipString);
        $ShipString=str_replace("Small_transport",$small_trans,$ShipString);
        $ShipString=str_replace("Large_transport",$large_trans,$ShipString);
        $ShipString=str_replace("Colony_ship",$colony_ship,$ShipString);
        $ShipString=str_replace("Solar_cell",$solar_cell,$ShipString);
        $ShipString=str_replace("Stealth_bomber",$stealth_bomber,$ShipString);
        $ShipString=str_replace("Imperial_starbase",$isb,$ShipString);
        $ShipString=str_replace("Light_graviton_cannon",$lgc,$ShipString);
        $ShipString=str_replace("Heavy_graviton_cannon",$hgc,$ShipString);
        $ShipString=str_replace("Ion_cannon",$ion_cannon,$ShipString);
        $ShipString=str_replace("Positron_lighter",$positron,$ShipString);
        $ShipString=str_replace("Interval_cannon",$ivc,$ShipString);
        $ShipString=str_replace("Laser_cannon_battery",$lcb,$ShipString);
        $ShipString=str_replace("Solar_cannon",$sc,$ShipString);
        $ShipString=str_replace("Small_shield_dome",$ssd,$ShipString);
        $ShipString=str_replace("Large_shield_dome",$lsd,$ShipString);
        $ShipsPlusAmt[$RoundNumb][$Part]=$ShipString;
        if($stop)
        {
            break 2;
        }
        if($Part=="Defense" or $Part=="Bomber")
        {
            continue;
        }
        if(!$ShipString)
        {
            $End=$RoundNumb." ".$Part;
            $ShipsPlusAmt[$RoundNumb][$Part]="\[color=".$color["destroyed"]."\]".$end_language['destroyed']."\[/color\]";
            if($Part=="Attack")
            $WinType="Defender";
            elseif($Part=="Defend")
            $WinType="Attacker";
            if($WinType=="Attacker")
            {
                break 2;
            }
            elseif($WinType=="Defender")
            {
                $stop=TRUE;
            }
        }
        elseif($RoundNumb==6 && $Part=="Defend")
        {
            $End=$RoundNumb." ".$Part;
            $WinType="Tie";
        }
    }
    $RoundNumb++;
}
return $ShipsPlusAmt;
}
$ShipsPlusAmt=ShipUpdate($ShipsPlusAmt,$end_language);
$DATA=$battle;
/* Bottom Section of Attack Report */
if($WinType=="Attack")
{
    $DATA=split($start_language['capture_start'],$DATA,2);
    $DATA[1]=trim($DATA[1]);
    $DATA=split($start_language['pig_iron'],$DATA[1],2);
    $Captured["Pig"]=$DATA[0];
    $Captured["Pig"]=str_replace(".","",$Captured["Pig"]);
    $DATA=split(",",$DATA[1],2);
    $DATA=split($start_language['metal'],$DATA[1],2);
    $DATA[0]=trim($DATA[0]);
    $Captured["Metal"]=$DATA[0];
    $Captured["Metal"]=str_replace(".","",$Captured["Metal"]);
    $DATA=split(",",$DATA[1],2);
    $DATA=split($start_language['krypto'],$DATA[1],2);
    $DATA[0]=trim($DATA[0]);
    $Captured["Kryptonite"]=$DATA[0];
    $Captured["Kryptonite"]=str_replace(".","",$Captured["Kryptonite"]);
    $DATA=split(",",$DATA[1],2);
    $DATA=split($start_language['spice'],$DATA[1],2);
    $DATA[0]=trim($DATA[0]);
    $Captured["Spice"]=$DATA[0];
    $Captured["Spice"]=str_replace(".","",$Captured["Spice"]);
}
$DATA=split($start_language['attack_lost'],$DATA[1],2);
$DATA=split($start_language['units'].".",$DATA[1],2);
$Units["Attack"]=$DATA[0];
$DATA=split($start_language['defend_lost'],$DATA[1],2);
$DATA=split($start_language['units'],$DATA[1],2);
$Units["Defend"]=$DATA[0];
foreach($Units as $side=>$amount)
{
    $Units[$side]=number_clean($Units[$side]);
}
$DATA=split($start_language['there_are_now'],$DATA[1],2);
$DATA=split($start_language['metal'],$DATA[1],2);
$Rubble["Metal"]=$DATA[0];
$Rubble["Metal"]=number_clean($Rubble["Metal"]);
if(!NEW_BATTLE_SCRIPT){$DATA=split($start_language['and'],$DATA[1],2);}
else{$DATA=split(",",$DATA[1],2);}
$DATA=split($start_language['krypto'],$DATA[1],2);
$Rubble["Kryptonite"]=$DATA[0];
$Rubble["Kryptonite"]=number_clean($Rubble["Kryptonite"]);
if(NEW_BATTLE_SCRIPT)
{
$DATA=split($start_language['and'],$DATA[1],2);
$DATA=split($start_language['spice'],$DATA[1],2);
$Rubble["Spice"]=$DATA[0];
$Rubble["Spice"]=number_clean($Rubble["Spice"]);
}
$DATA=explode(". ",$DATA[1],2);
$DATA=split($start_language['astro_chance'],$DATA[0],2);
$DATA=split("\%",$DATA[1],2);
$Asteriod["Chance"]=$DATA[0];
$Asteriod["Form"]=FALSE;
if($Asteroid["Chance"]=="")
$Asteriod["Form"]=TRUE;
###############################
#####Formatting Section########
###############################
function format_color($color_array_key,$input)
{
    if(!is_null($GLOBALS['color'][$color_array_key]))
    {
        $output="[color=".$GLOBALS['color'][$color_array_key]."]".$input."[/color]";
    }
    else
    $output=$input;
    return $output;
}
$Final['BBcode']="[center]";
if(!is_null($color['default_color']))
    $Final['Top']="[color=".$color['default_color']."]";
else
    $Final['Top']="";
$Final['Top'] .="[b]".$end_language['StartSentence']." ".$DateTime."[/b]";
if(!is_null($color['default_color']))
    $Final['Top'] .="[/color]";
$upper_round=strtoupper($end_language['round']);
if($ShipsPlusAmt['Stealth']['Bomber']!=$end_language['stealth_bomber']." "){
$Final['Stealth_Start']=format_color("default_color",$upper_round."-"."STEALTH BOMBER FIRST STRIKE");
$Final['Stealth_Attacker_Name']=format_color("default_color",$end_language["Attacker"]." ".$Attacker);
$Final['Stealth_Ships']=$ShipsPlusAmt['Stealth']['Bomber'];
$Final['Stealth_Defender_Name']=format_color("default_color",$end_language["Defender"]." ".$Defender);
$Final['Stealth_Defenses']=$ShipsPlusAmt['Stealth']['Defense'];
$Final['Seperate']="\n";}
$Final['Round1']=$upper_round." -1-";
$Final['Attacker-Round1']=format_color("attacker_color",$end_language['Attacker']." ".$Attacker);
$Final['Attacker_Ships-Round1']=$ShipsPlusAmt[1]['Attack'];
$Final['Defender-Round1']="\n".format_color("defender_color",$end_language['Defender']." ".$Defender);
$Final['Defener_Ships-Round1']=$ShipsPlusAmt[1]['Defend'];
$RoundAndSideEnd=explode(" ",$End);
$Final_Round=$RoundAndSideEnd[0];
$End_Side=$RoundAndSideEnd[1];
$Final_Round+=0;//Change to numeric
foreach($Captured as $field=>$value)
{
    settype($Captured[$field],"integer");
}
foreach($Units as $field=>$value)
{
    settype($Units[$field],"integer");
}
foreach($Rubble as $field=>$value)
{
    settype($Rubble[$field],"integer");
}
if($Final_Round <> 1){
    $Final['Final_Round']=format_color("default_color",$upper_round." "."-".$Final_Round_string."-");
    $Final['Attacker-FinalRound']=format_color("attacker_color",$end_language['Attacker']." ".$Attacker);
    $Final['Attacker_Ships-Final']=$ShipsPlusAmt[$Final_Round]['Attack'];
    $Final['Defender-FinalRound']="\n".format_color("defender_color",$end_language['Defender']." ".$Defender);
    $Final['Defener_Ships-Final']=$ShipsPlusAmt[$Final_Round]['Defend'];
}
$WinKey=$WinType."_win";
$Final['Win-Sentence']=format_color("bottom_basic",$end_language[$WinKey]);
if($WinType=="Attacker")
{
    $Capture_Sentence=$end_language['capture_start']." ".number_format($Captured["Pig"],0,"",".")." ".$end_language['pig_iron'].","." ".number_format($Captured["Metal"],0,"",".")." ".$end_language['metal'].","." ".number_format($Captured["Kryptonite"],0,"",".")." ".$end_language['krypto'].","." ".$end_language['and']." ".number_format($Captured["Spice"],0,"",".")." ".$end_language['spice'].".";
    $Final['Capture_Sentence']=format_color("capture",$Capture_Sentence);
}
$Attacker_Lost=$end_language['attack_lost']." ".number_format($Units["Attack"],0,"",".")." ".$end_language['units'].".";
$Final['Attacker_Lost']=format_color("bottom_basic",$Attacker_Lost);
$Defender_Lost=$end_language['defend_lost']." ".number_format($Units["Defend"],0,"",".")." ".$end_language['units'].".";
$Final['Defender_Lost']=format_color("defend_lost",$Defender_Lost);
$Rubble_Sentence=$end_language['there_are_now']." ".number_format($Rubble["Metal"],0,"",".")." ".$end_language['metal'];
if(!NEW_BATTLE_SCRIPT){$Rubble_Sentence .=" ".$end_language['and']." ";}
else{$Rubble_Sentence .=","." ";}
$Rubble_Sentence .=number_format($Rubble["Kryptonite"],0,"",".")." ".$end_language['krypto'];
if(NEW_BATTLE_SCRIPT){$Rubble_Sentence .=" ".$end_language['and']." ".number_format($Rubble["Spice"],0,"",".")." ".$end_language['spice'];}
$Final['Rubble_Sentence']=format_color("bottom_basic",$Rubble_Sentence);
if($Asteroid["Form"])
{
    $Final['Asteroid']=format_color("default_color",$end_language['astro_form']);
}
else
{
    $Final['Asteroid']=format_color("default_color",$end_language['astro_chance']." ".number_format($Asteroid["Chance"],0,"",".")."%");
}
$Final['BBCodeEnd']="[/center]";
$Converted=implode("\n\n",$Final);
?>


The part that the str_replace isn't working in is in the function ShipUpdate:

function ShipUpdate(&$ShipsPlusAmt,$end_language){
    $RoundNumb=1;
    extract($end_language);
    foreach($ShipsPlusAmt as $Round)
    {
        foreach($Round as $Part=>$ShipString)
        {
            $ShipString=str_replace("Spy_probe",$spy_probe,$ShipString);
            $ShipString=str_replace("Small_fighter",$small_fighter,$ShipString);
            $ShipString=str_replace("Small_transport",$small_trans,$ShipString);
            $ShipString=str_replace("Large_transport",$large_trans,$ShipString);
            $ShipString=str_replace("Colony_ship",$colony_ship,$ShipString);
            $ShipString=str_replace("Solar_cell",$solar_cell,$ShipString);
            $ShipString=str_replace("Stealth_bomber",$stealth_bomber,$ShipString);
            $ShipString=str_replace("Imperial_starbase",$isb,$ShipString);
            $ShipString=str_replace("Light_graviton_cannon",$lgc,$ShipString);
            $ShipString=str_replace("Heavy_graviton_cannon",$hgc,$ShipString);
            $ShipString=str_replace("Ion_cannon",$ion_cannon,$ShipString);
            $ShipString=str_replace("Positron_lighter",$positron,$ShipString);
            $ShipString=str_replace("Interval_cannon",$ivc,$ShipString);
            $ShipString=str_replace("Laser_cannon_battery",$lcb,$ShipString);
            $ShipString=str_replace("Solar_cannon",$sc,$ShipString);
            $ShipString=str_replace("Small_shield_dome",$ssd,$ShipString);
            $ShipString=str_replace("Large_shield_dome",$lsd,$ShipString);
            $ShipsPlusAmt[$RoundNumb][$Part]=$ShipString;
            if($stop)
            {
                break 2;
            }
            if($Part=="Defense" or $Part=="Bomber")
            {
                continue;
            }
            if(!$ShipString)
            {
                $End=$RoundNumb." ".$Part;
                $ShipsPlusAmt[$RoundNumb][$Part]="\[color=".$color["destroyed"]."\]".$end_language['destroyed']."\[/color\]";
                if($Part=="Attack")
                $WinType="Defender";
                elseif($Part=="Defend")
                $WinType="Attacker";
                if($WinType=="Attacker")
                {
                    break 2;
                }
                elseif($WinType=="Defender")
                {
                    $stop=TRUE;
                }
            }
            elseif($RoundNumb==6 && $Part=="Defend")
            {
                $End=$RoundNumb." ".$Part;
                $WinType="Tie";
            }
        }
        $RoundNumb++;
    }
    return $ShipsPlusAmt;
}

It also didn't work when it was out of function, so I really don't know the problem.


If you need the languages.php page, where the $end_language array is, here it is:

<?php
require_once("connect.php");
$connect=mysqli_connect(SERVER_LOC,SERVER_USER,SERVER_PASS,DATABASE_NAME) or die("Could not connect to server");
if($_POST['StartLang']!="Select a starting language" && !is_null($_POST['StartLang']))
{
    $query="SELECT * FROM `Languages` WHERE `lang_Key`='".$_POST['StartLang']."'";
}
else
{
    $query="SELECT * FROM `Languages` WHERE `lang_Key`='EN'";
}
$results=mysqli_query($connect,$query);
$start_language=mysqli_fetch_assoc($results);
unset($start_language["username"],$start_language["langName"]);
if($_POST['EndLang']!="Select a result language" && !is_null($_POST['EndLang']))
{
    $query="SELECT * FROM `Languages` WHERE `lang_Key`='".$_POST['EndLang']."'";
}
elseif($_POST['StartLang']=="Select a starting language")
{
    $query="SELECT * FROM `Languages` WHERE `lang_Key`='EN'";
}
else
{
    $query="SELECT * FROM `Languages` WHERE `lang_Key`='".$_POST['StartLang']."'";
}
$results=mysqli_query($connect,$query);
$end_language=mysqli_fetch_assoc($results);
if($start_language["lang_Key"]=="EN" && !($_POST['EndLang']!="Select a result language" && !is_null($_POST['EndLang'])))
    $end_language=$start_language;
unset($end_language["lang_Key"],$end_language["username"],$end_language["langName"],$start_language["lang_Key"]);
mysqli_close($connect);
?>

I know that the database connects, so that isn't the problem.  $end_language is defined exactly how I want it, the str_replace just doesn't work.

Re: PHP help (str_replace isn't working)

Try to debug the function "ShipUpdate" with help of var_dump function or some debug tools for PHP.

3 (edited by jkmaster9918 2009-09-15 23:12)

Re: PHP help (str_replace isn't working)

Well, I finally got it to work. It just took a little messing around.


Edit: Now I have a new problem.  I want to make my program work on PHP6.0.0+ systems, which means that I need to get rid of the split and ereg_replace functions, and replace them with explode and str_replace (I never really used the ereg_replace function correctly).  Can anyone help me with this?


PS: This is the updated page that now works:

<?php
error_reporting(E_ERROR | E_PARSE);
require("./settings.php");
require_once("languages.php");
require("styles.php");
function Color_Bind($ShipName,$Amount,$D1)
{
    global $color;
    $bound="[color=".$color[$ShipName]."]".$ShipName.$D1.$Amount."[".'/'."color]";
    return $bound;
}
function Merge($ShipArray,$AmountArray,$D1,$D2)
{
    foreach($ShipArray as $field=>$value)
    {
        $value=trim($value);
        $value=ereg_replace('    ','',$value);
        $value=trim($value);
        $AmountArray[$field]=trim($AmountArray[$field]);
        $AmountArray[$field]=ereg_replace(' ','',$AmountArray[$field]);
        $AmountArray[$field]=str_replace('.','',$AmountArray[$field]);
        $AmountArray[$field]=trim($AmountArray[$field]);
        $ShipAmount[$value]=$AmountArray[$field];
    }
    foreach($ShipAmount as $Ship=>$Amount)
    {
        $ShipAndAmount[]=Color_Bind($Ship,$Amount,$D1);
    }
    $timesThrough=0;
    $sizeDown1=sizeof($ShipAndAmount)-1;
    foreach($ShipAndAmount as $key=>$value)
    {
        if($timesThrough==$sizeDown1)
        {
            unset($ShipAndAmount[$key]);
        }
        else
        {
            $timesThrough++;
        }
    }
    $RoundPart=implode($D2,$ShipAndAmount);
    return $RoundPart;
}
function number_clean($number_string)
{
    if(is_array($number_string))
    {
        foreach($number_string as $field=>$number)
        {
            $number_string[$field]=ereg_replace("    ","",$number_string[$field]);
            $number_string[$field]=trim($number_string[$field]);
            $number_string[$field]=str_replace(".","",$number_string[$field]);
        }
    }
    else
    {
        $number_string=ereg_replace("    ","",$number_string);
        $number_string=trim($number_string);
        $number_string=str_replace(".","",$number_string);
    }
    return $number_string;
}
function number_reformat($number)
{
    if(is_array($number))
    {
        foreach($number as $field=>$number)
        {
            $number_array=str_split($number);
            foreach($number_array as $key=>$digit)
            {
                $mod_test_1=sizeof($number_array) % 3;
                $new_numb_key=sizeof($number_array)-$key;
                $test_mod=$new_numb_key % 3;
                if($test_mod == 0 && $new_numb_key<>sizeof($number_array))
                {
                    $new_numb[$new_numb_key]=".".$digit;
                }
                else
                {
                    $new_numb[$new_numb_key]=$digit;
                }
        }
        $number=implode("",$new_numb);
        }
    }
    else
    {
        $number_array=str_split($number);
        foreach($number_array as $key=>$digit)
        {
            $mod_test_1=sizeof($number_array) % 3;
                $new_numb_key=sizeof($number_array)-$key;
                $test_mod=$new_numb_key % 3;
                if($test_mod == 0 && $new_numb_key<>sizeof($number_array))
                {
                    $new_numb[$new_numb_key]=".".$digit;
                }
                else
                {
                    $new_numb[$new_numb_key]=$digit;
                }
        }
        $number=implode("",$new_numb);
    }
    return $number;
}
function word_clean($string)
{
    if(is_array($string))
    {
        foreach($string as $field=>$string)
        {
            $string[$field]=str_replace("    ","",$string[$field]);
            $string[$field]=trim($string[$field]);
        }
    }
    else
    {
        $string=str_replace("    ","",$string);
        $string=trim($string);
    }
    return $string;
}
function StealthMergeDefend($ShipArray,$BeforeArray,$AfterArray,$D1,$BtoAseperator,$D2,$Headers=TRUE)
{
    if($Headers)
    {
        global $end_language;
        $HeaderHide=$end_language['type'];
        $Header[]=$end_language['number_before'];
        $Header[]=$end_language['number_after'];
        $Headers=implode($BtoAseperator,$Header);
        $HeadersTrue[]=$HeaderHide;
        $HeadersTrue[]=$Headers;
        $All[]=implode($D1,$HeadersTrue);
    }
    if(sizeof($ShipArray)==sizeof($BeforeArray) and sizeof($BeforeArray)==sizeof($AfterArray))
    {
        foreach($ShipArray as $field=>$ShipName)
        {
            $Before[$ShipName]=$BeforeArray[$field];
            $After[$ShipName]=$AfterArray[$field];
        }
        foreach ($Before as $Ship=>$Amount)
        {
            global $color;
            $Merge[]="[color=".$color[$Ship]."]";
            $Merge[]=$Ship;
            $Merge[]=$Amount;
            $NameandBefore[$Ship]=implode($D1,$Merge);
            unset($Merge);
        }
        foreach($After as $Ship=>$Amount)
        {
            $Merge[]=$NameandBefore[$Ship];
            $Merge[]=$Amount."[/color]";
            $All[]=implode($BtoAseperator,$Merge);
            unset($Merge);
        }
        $StealthRound=implode($D2,$All);
        return $StealthRound;
    }
    else
    return;
}
$DATA=$battle;
/* Replace spaces in ship names with underscores */
$DATA=str_replace($start_language['spy_probe'],"Spy_probe",$DATA);
$DATA=str_replace($start_language['small_fighter'],"Small_fighter",$DATA);
$DATA=str_replace($start_language['small_trans'],"Small_transport",$DATA);
$DATA=str_replace($start_language['large_trans'],"Large_transport",$DATA);
$DATA=str_replace($start_language['colony_ship'],"Colony_ship",$DATA);
$DATA=str_replace($start_language['solar_cell'],"Solar_cell",$DATA);
$DATA=str_replace($start_language['stealth_bomber'],"Stealth_bomber",$DATA);
$DATA=str_replace($start_language['isb'],"Imperial_starbase",$DATA);
$DATA=str_replace($start_language['lgc'],"Light_graviton_cannon",$DATA);
$DATA=str_replace($start_language['hgc'],"Heavy_graviton_cannon",$DATA);
$DATA=str_replace($start_language['hgc'],"Ion_cannon",$DATA);
$DATA=str_replace($start_language['positron'],"Positron_lighter",$DATA);
$DATA=str_replace($start_language['ivc'],"Interval_cannon",$DATA);
$DATA=str_replace($start_language['lcb'],"Laser_cannon_battery",$DATA);
$DATA=str_replace($start_language['sc'],"Solar_cannon",$DATA);
$DATA=str_replace($start_language['ssd'],"Small_shield_dome",$DATA);
$DATA=str_replace($start_language['lsd'],"Large_shield_dome",$DATA);
$DATA=preg_replace("/\n/"," ",$DATA);
$DATA=split($start_language['StartSentence']." ",$DATA,2);
$DATA=split(" :",$DATA[1],2);
$DateTime=$DATA[0];
$DATA=spliti($start_language['round']." - 1 -",$DATA[1],2);
$Stealth=$DATA[0];
/* Stealth Section */
$Stealth=split($start_language['Defender'],$Stealth,2);
$StealthRound["SBAmt_Attack"]=split($start_language['number'],$Stealth[0],2);
$StealthRound["SBAmt_Attack"]=number_clean($StealthRound["SBAmt_Attack"]);
$StealthRound["SBAmt_Attack"]=$StealthRound["SBAmt_Attack"][1];
$Stealth=split($start_language['type'],$Stealth[1],2);
$Stealth=split($start_language['number_before'],$Stealth[1],2);
$StealthRound["Defend_Item_Name"]=word_clean($Stealth[0]);
$Stealth=split($start_language['number_after'],$Stealth[1],2);
$StealthRound["Defend_Item_Before"]=number_clean($Stealth[0]);
$Stealth=split($start_language['stealth_start'],$Stealth[1],2);
$StealthRound["Defend_Item_After"]=number_clean($Stealth[0]);
$Stealth=split($start_language['stealth_end'],$Stealth[1],2);
$StealthRound["Destroyed_Items"]=number_clean($Stealth[0]);
$StealthRound["Defend_Item_Name"]=split(" ",$StealthRound["Defend_Item_Name"]);
$StealthRound["Defend_Item_Before"]=split(" ",$StealthRound["Defend_Item_Before"]);
$StealthRound["Defend_Item_After"]=split(" ",$StealthRound["Defend_Item_After"]);
$ShipsPlusAmt["Stealth"]["Bomber"]="[color=".$color['Stealth_bomber']."]Stealth_bomber".$style['ShipName-Number-Seperator'].$StealthRound["SBAmt_Attack"]."[/color]";
$ShipsPlusAmt["Stealth"]["Defense"]=StealthMergeDefend($StealthRound["Defend_Item_Name"],$StealthRound["Defend_Item_Before"],$StealthRound["Defend_Item_After"],$style['ShipName-Number-Seperator'],$style["Stealth-BtoAseperator"],"\n");
/* Round 1 */
$DATA=spliti($start_language['round']." - 2 -",$DATA[1],2);
$Round1=$DATA[0];
$Round1=split($start_language['Attacker'],$Round1,2);
$Round1=split($start_language['Defender'],$Round1[1],2);
$Attack=$Round1[0];
$Attack=split("\[",$Attack,2);
$Attacker=trim($Attack[0]);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[1]['Attack']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round1[1];
$Defend=split("\[",$Defend,2);
$Defender=trim($Defend[0]);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language['round'],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[1]['Defend']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
unset($ShipAmt,$Ships,$ShipsAmt);
unset($Attack,$Defend);
/* Round 2 */
$DATA=spliti($start_language['round']." - 3 -",$DATA[1],2);
$Round2=$DATA[0];
$Round2=split($start_language['Attacker'],$Round2,2);
$Round2=split($start_language['Defender'],$Round2[1],2);
$Attack=$Round2[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[2]['Attack']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round2[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language['round'],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[2]['Defend']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
unset($Attack,$Defend);
/* Round 3 */
$DATA=spliti($start_language['round']." - 4 -",$DATA[1],2);
$Round3=$DATA[0];
$Round3=split($start_language['Attacker'],$Round3,2);
$Round3=split($start_language["Defender"],$Round3[1],2);
$Attack=$Round3[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[3]['Attack']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round3[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language['round'],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[3]['Defend']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
unset($Attack,$Defend);
/* Round 4 */
$DATA=spliti($start_language['round']." - 5 -",$DATA[1],2);
$Round4=$DATA[0];
$Round4=split($start_language["Attacker"],$Round4,2);
$Round4=split($start_language["Defender"],$Round4[1],2);
$Attack=$Round4[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[4]['Attack']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round4[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language["round"],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[4]['Defend']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
/* Round 5 */
$DATA=spliti($start_language['round']." - 6 -",$DATA[1],2);
$Round5=$DATA[0];
$Round5=split($start_language["Attacker"],$Round5,2);
$Round5=split($start_language["Defender"],$Round5[1],2);
$Attack=$Round5[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[5]['Attack']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round5[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language["round"],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[5]['Defend']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
/* Round 6 */
$Round6=$DATA[1];
$Round6=split($start_language["Attacker"],$Round5,2);
$Round6=split($start_language["Defender"],$Round5[1],2);
$Attack=$Round6[0];
$Attack=split($Attacker,$Attack);
$Attack=split($start_language['type'],$Attack[1],2);
$Attack=split($start_language['number'],$Attack[1],2);
$Ships=split(" ",$Attack[0]);
unset($Ships[0]);
$Attack=spliti($start_language['round'],$Attack[1],2);
$ShipAmt=split(" ",$Attack[0]);
$ShipsPlusAmt[6]['Attack']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
unset($ShipAmt,$Ships,$ShipsAmt);
$Defend=$Round6[1];
$Defend=split($Defender,$Defend);
$Defend=split($start_language['type'],$Defend[1],2);
$Defend=split($start_language['number'],$Defend[1],2);
$Ships=split(" ",$Defend[0]);
unset($Ships[0]);
$Defend=spliti($start_language["round"],$Defend[1],2);
$ShipAmt=split(" ",$Defend[0]);
$ShipsPlusAmt[6]['Defend']=Merge($Ships,$ShipAmt,$style['ShipName-Number-Seperator'],"\n");
/* Figure out Last Round and switch ship names back */
function ShipUpdate($ShipsPlusAmt,$end_language){
    $RoundNumb=0;
    extract($end_language);
    foreach($ShipsPlusAmt as $Round)
    {
        foreach($Round as $Part=>$ShipString)
        {
            $ShipString=str_replace("Spy_probe",$spy_probe,$ShipString);
            $ShipString=str_replace("Small_fighter",$small_fighter,$ShipString);
            $ShipString=str_replace("Small_transport",$small_trans,$ShipString);
            $ShipString=str_replace("Large_transport",$large_trans,$ShipString);
            $ShipString=str_replace("Colony_ship",$colony_ship,$ShipString);
            $ShipString=str_replace("Solar_cell",$solar_cell,$ShipString);
            $ShipString=str_replace("Stealth_bomber",$stealth_bomber,$ShipString);
            $ShipString=str_replace("Imperial_starbase",$isb,$ShipString);
            $ShipString=str_replace("Light_graviton_cannon",$lgc,$ShipString);
            $ShipString=str_replace("Heavy_graviton_cannon",$hgc,$ShipString);
            $ShipString=str_replace("Ion_cannon",$ion_cannon,$ShipString);
            $ShipString=str_replace("Positron_lighter",$positron,$ShipString);
            $ShipString=str_replace("Interval_cannon",$ivc,$ShipString);
            $ShipString=str_replace("Laser_cannon_battery",$lcb,$ShipString);
            $ShipString=str_replace("Solar_cannon",$sc,$ShipString);
            $ShipString=str_replace("Small_shield_dome",$ssd,$ShipString);
            $ShipString=str_replace("Large_shield_dome",$lsd,$ShipString);
            if($RoundNumb==0)
                $ShipsPlusAmt["Stealth"][$Part]=$ShipString;
            $ShipsPlusAmt[$RoundNumb][$Part]=$ShipString;
            if($stop)
            {
                break 2;
            }
            if($Part=="Defense" or $Part=="Bomber")
            {
                continue;
            }
            if(!$ShipString)
            {
                $End=$RoundNumb." ".$Part;
                $ShipsPlusAmt[$RoundNumb][$Part]="[color=".$GLOBALS["color"]["destroyed"]."]".$destroyed."[/color]";
                if($Part=="Attack")
                $WinType="Defender";
                elseif($Part=="Defend")
                $WinType="Attacker";
                if($WinType=="Attacker")
                {
                    break 2;
                }
                elseif($WinType=="Defender")
                {
                    $stop=TRUE;
                }
            }
            elseif($RoundNumb==6 && $Part=="Defend")
            {
                $End=$RoundNumb." ".$Part;
                $WinType="Tie";
            }
        }
        $RoundNumb++;
    }
    $Info["ShipsPlusAmt"]=$ShipsPlusAmt;
    $Info["End"]=$End;
    $Info["WinType"]=$WinType;
    return $Info;
}
$Info=call_user_func("ShipUpdate",$ShipsPlusAmt,$end_language,$End,$WinType);
extract($Info);
$DATA=$battle;
/* Bottom Section of Attack Report */
if($WinType=="Attacker")
{
    $DATA=split($start_language['capture_start'],$DATA,2);
    $DATA[1]=trim($DATA[1]);
    $DATA=split($start_language['pig_iron'],$DATA[1],2);
    $Captured["Pig"]=$DATA[0];
    $Captured["Pig"]=str_replace(".","",$Captured["Pig"]);
    $DATA=split(",",$DATA[1],2);
    $DATA=split($start_language['metal'],$DATA[1],2);
    $DATA[0]=trim($DATA[0]);
    $Captured["Metal"]=$DATA[0];
    $Captured["Metal"]=str_replace(".","",$Captured["Metal"]);
    $DATA=split(",",$DATA[1],2);
    $DATA=split($start_language['krypto'],$DATA[1],2);
    $DATA[0]=trim($DATA[0]);
    $Captured["Kryptonite"]=$DATA[0];
    $Captured["Kryptonite"]=str_replace(".","",$Captured["Kryptonite"]);
    $DATA=split(",",$DATA[1],2);
    $DATA=split($start_language['spice'],$DATA[1],2);
    $DATA[0]=trim($DATA[0]);
    $Captured["Spice"]=$DATA[0];
    $Captured["Spice"]=str_replace(".","",$Captured["Spice"]);
}
$DATA=split($start_language['attack_lost'],$DATA[1],2);
$DATA=split($start_language['units'].".",$DATA[1],2);
$Units["Attack"]=$DATA[0];
$DATA=split($start_language['defend_lost'],$DATA[1],2);
$DATA=split($start_language['units'],$DATA[1],2);
$Units["Defend"]=$DATA[0];
foreach($Units as $side=>$amount)
{
    $Units[$side]=number_clean($Units[$side]);
}
$DATA=split($start_language['there_are_now'],$DATA[1],2);
$DATA=split($start_language['metal'],$DATA[1],2);
$Rubble["Metal"]=$DATA[0];
$Rubble["Metal"]=number_clean($Rubble["Metal"]);
if(!NEW_BATTLE_SCRIPT){$DATA=split($start_language['and'],$DATA[1],2);}
else{$DATA=split(",",$DATA[1],2);}
$DATA=split($start_language['krypto'],$DATA[1],2);
$Rubble["Kryptonite"]=$DATA[0];
$Rubble["Kryptonite"]=number_clean($Rubble["Kryptonite"]);
if(NEW_BATTLE_SCRIPT)
{
$DATA=split($start_language['and'],$DATA[1],2);
$DATA=split($start_language['spice'],$DATA[1],2);
$Rubble["Spice"]=$DATA[0];
$Rubble["Spice"]=number_clean($Rubble["Spice"]);
}
$DATA=explode(". ",$DATA[1],2);
$DATA=split($start_language['astro_chance'],$DATA[0],2);
$DATA=split("\%",$DATA[1],2);
$Asteriod["Chance"]=$DATA[0];
$Asteriod["Form"]=FALSE;
if($Asteroid["Chance"]=="")
$Asteriod["Form"]=TRUE;
###############################
#####Formatting Section########
###############################
function format_color($color_array_key,$input)
{
    if($GLOBALS['color'][$color_array_key]!== NULL)
    {
        $output="[color=".$GLOBALS['color'][$color_array_key]."]".$input."[/color]";
    }
    else
    $output=$input;
    return $output;
}
$Final['BBcode']="[center]";
if(!is_null($color['default_color']))
    $Final['Top']="[color=".$color['default_color']."]";
else
    $Final['Top']="";
$Final['Top'] .="[b]".$end_language['StartSentence']." ".$DateTime."[/b]";
if(!is_null($color['default_color']))
    $Final['Top'] .="[/color]";
$upper_round=strtoupper($end_language['round']);
if($ShipsPlusAmt['Stealth']['Bomber']!="[color=".$color['Stealth_bomber']."]".$end_language['stealth_bomber'].$style['ShipName-Number-Seperator'].$StealthRound["SBAmt_Attack"]."[/color]"){
$Final['Stealth_Start']=format_color("default_color",$upper_round."-"."STEALTH BOMBER FIRST STRIKE");
$Final['Stealth_Attacker_Name']=format_color("default_color",$end_language["Attacker"]." ".$Attacker);
$Final['Stealth_Ships']=$ShipsPlusAmt['Stealth']['Bomber'];
$Final['Stealth_Defender_Name']=format_color("default_color",$end_language["Defender"]." ".$Defender);
$Final['Stealth_Defenses']=$ShipsPlusAmt['Stealth']['Defense'];
$Final['Seperate']="\n";}
$Final['Round1']=format_color("default_color",$upper_round." -1-");
$Final['Attacker-Round1']=format_color("attacker_color",$end_language['Attacker']." ".$Attacker);
$Final['Attacker_Ships-Round1']=$ShipsPlusAmt[1]['Attack'];
$Final['Defender-Round1']="\n".format_color("defender_color",$end_language['Defender']." ".$Defender);
$Final['Defener_Ships-Round1']=$ShipsPlusAmt[1]['Defend'];
$RoundAndSideEnd=explode(" ",$End);
$Final_Round=$RoundAndSideEnd[0];
$End_Side=$RoundAndSideEnd[1];
$Final_Round+=0;//Change to numeric
foreach($Captured as $field=>$value)
{
    settype($Captured[$field],"integer");
}
foreach($Units as $field=>$value)
{
    settype($Units[$field],"integer");
}
foreach($Rubble as $field=>$value)
{
    settype($Rubble[$field],"integer");
}
if($Final_Round <> 1){
    $Final['Final_Round']=format_color("default_color",$upper_round." "."-"."$Final_Round"."-");
    $Final['Attacker-FinalRound']=format_color("attacker_color",$end_language['Attacker']." ".$Attacker);
    $Final['Attacker_Ships-Final']=$ShipsPlusAmt[$Final_Round]['Attack'];
    $Final['Defender-FinalRound']="\n".format_color("defender_color",$end_language['Defender']." ".$Defender);
    $Final['Defener_Ships-Final']=$ShipsPlusAmt[$Final_Round]['Defend'];
}
$WinKey=$WinType."_win";
$Final['Win-Sentence']=format_color("bottom_basic",$end_language[$WinKey]);
if($WinType=="Attacker")
{
    $Capture_Sentence=$end_language['capture_start']." ".number_format($Captured["Pig"],0,"",".")." ".$end_language['pig_iron'].","." ".number_format($Captured["Metal"],0,"",".")." ".$end_language['metal'].","." ".number_format($Captured["Kryptonite"],0,"",".")." ".$end_language['krypto'].","." ".$end_language['and']." ".number_format($Captured["Spice"],0,"",".")." ".$end_language['spice'].".";
    $Final['Capture_Sentence']=format_color("capture",$Capture_Sentence);
}
$Attacker_Lost=$end_language['attack_lost']." ".number_format($Units["Attack"],0,"",".")." ".$end_language['units'].".";
$Final['Attacker_Lost']=format_color("bottom_basic",$Attacker_Lost);
$Defender_Lost=$end_language['defend_lost']." ".number_format($Units["Defend"],0,"",".")." ".$end_language['units'].".";
$Final['Defender_Lost']=format_color("defend_lost",$Defender_Lost);
$Rubble_Sentence=$end_language['there_are_now']." ".number_format($Rubble["Metal"],0,"",".")." ".$end_language['metal'];
if(!NEW_BATTLE_SCRIPT){$Rubble_Sentence .=" ".$end_language['and']." ";}
else{$Rubble_Sentence .=","." ";}
$Rubble_Sentence .=number_format($Rubble["Kryptonite"],0,"",".")." ".$end_language['krypto'];
if(NEW_BATTLE_SCRIPT){$Rubble_Sentence .=" ".$end_language['and']." ".number_format($Rubble["Spice"],0,"",".")." ".$end_language['spice'];}
$Final['Rubble_Sentence']=format_color("bottom_basic",$Rubble_Sentence);
if($Asteroid["Form"])
{
    $Final['Asteroid']=format_color("default_color",$end_language['astro_form']);
}
else
{
    $Final['Asteroid']=format_color("default_color",$end_language['astro_chance']." ".number_format($Asteroid["Chance"],0,"",".")."%");
}
$Final['BBCodeEnd']="[/center]";
$Converted=implode("\n\n",$Final);
?>

I tried to just change the functions, but that didn't really work to well (it completely failed)

Re: PHP help (str_replace isn't working)

The line

        $AmountArray[$field]=ereg_replace(' ','',$AmountArray[$field]);

will be:

        $AmountArray[$field]=str_replace(' ','',$AmountArray[$field]);

Here is the descriptions of explode and str_replace functions.

Re: PHP help (str_replace isn't working)

I found the one error that I made.  When I was making the change, I switched this line:

$Attack=split("\[",$Attack,2);

and this line

$Defend=split("\[",$Defend,2);

to

$Attack=explode("\[",$Attack,2);

and

$Defend=explode("\[",$Defend,2);

instead of

$Attack=explode("[",$Attack,2);

and

$Defend=explode("[",$Defend,2);

which messed it up.  Once I fixed that it worked.

6

Re: PHP help (str_replace isn't working)

As I remember from php tutorials If search and replace are arrays, then str_replace() takes a value from each array and uses them to do search and replace on subject. If replace has fewer values than search, then an empty string is used for the rest of replacement values. If search is an array and replace is a string, then this replacement string is used for every value of search. The converse would not make sense, though.