MikeV
MikeV

Reputation: 3

Using an explode array in an if statement

first post. Been searching through here all day to figure out a problem.

I am using a form to upload a .txt with an array in this format:

"var1","var2","var3","var4"...etc

and here is my code:

<?php

$file = $_FILES['uploaded_file']['tmp_name'];
$file2 = nl2br(file_get_contents($file));
$file3 = str_replace('"' , '' , $file2);
$file4 = str_replace('ÿþ' , '' , $file3);
$line_break = explode("<br />" , $file4);
$topchange=105;
  foreach ($line_break as $final1) {

   $final2 = explode("," , $final1);
     $regex = '#\((([^()]+|(?R))*)\)#';
     preg_match($regex, $final1, $match);

        if($final2[4] == "DF") {
            $type == "DF";
        } else { $type == "S"; }

     echo "<div style='position:absolute;TOP:". $topchange .";LEFT:395;'>". $final2[1] ."</div>";
     echo "<div style='position:absolute;TOP:". $topchange .";LEFT:446;'>". $final2[3] ."</div>";
     echo "<div style='position:absolute;TOP:". $topchange .";LEFT:365;'>". $match[0] ."</div>";
     echo "<div style='position:absolute;TOP:". $topchange .";LEFT:335;'>". $type ."</div>";
     echo "<div style='position:absolute;TOP:". $topchange .";LEFT:520;'>". $final2[6] ."</div>";
        $changeamt = 24.2;
        $topchange = $topchange + $changeamt;



  }


?>

Sorry if my format is terrible but its working for me. My problem is in the simple if statement. I've echo'd the $final2[4] to make sure it is outputting plain text. As far as I can see, page and page source, it is coming out as various small strings of text (TE,WE,BE,P,S, and DF). I basically want every string to change to S unless it is DF in which case it will stay the same.

Been working on this for a while and cannot figure it out.

Upvotes: 0

Views: 103

Answers (1)

diegonalvarez
diegonalvarez

Reputation: 106

Inside your if you must assign and no compare, your code look like this:

if($final2[4] == "DF") {
    $type == "DF";
} else {
    $type == "S";
}

And you should do this:

$type = "S";
if($final2[4] == "DF") {
    $type = "DF";
}

Upvotes: 3

Related Questions