0

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.

1 Answer 1

3

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";
}
Sign up to request clarification or add additional context in comments.

1 Comment

In this case you assign $df but it may have other value. The proper code is : $df = ($final2[4]!=='DF') ? 'S' : 'DF';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.