0

I want to compare to a string but it is not working.

First I took it in my script and stored in a variable, and after that I stored the variable in the session.

This is my code...

<?php
    $currencyName1 = "<script>document.write(data);</script>";

    $_SESSION["currencyVal"] = $currencyName1;

    $price = strip_tags($this->session->userdata('currencyVal'));
    $price1 = substr($price,14,17);

    if (strcmp($price,"SAR")) {
        echo "SAR"; 
    } else {
        echo "USD"; 
    }
?>
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263

2 Answers2

0

Use cookie to get proper string Where as in $_SESSION you get value with script tags <script>document.write(data);</script>

Shareque
  • 361
  • 4
  • 23
0

Agreed with @lehmanad1, You need to perform comparison like strcmp($price1,"SAR"), and keep in mind that strcmp return result as follows.

strcmp returns:
0 - if the two strings are equal
<0 - if string1 is less than string2
>0 - if string1 is greater than string2

so that in your case the if condition return 0 if strcmp($price1,"SAR")gets true, and thus else condition will be executed.

you need to try following approach.

if (strcmp($price1,"SAR")==0) {
    echo "SAR"; 
} else {
    echo "USD"; 
}