Support

Account

Home Forums Front-end Issues Compare field with string

Solved

Compare field with string

  • Hello,

    I’ve a question, seems to be little idiot.

    I’ve a custom field, text type and a string, if I echo the two elements, I’ve same result, but if I compare it, they are not the same. I don’t understand why.

    My code :

    $lien = get_field('fieldName');
    echo $lien.'<br/>';
    $lien2 = 'http://link.com';
    echo $lien2.'<br/>';
    if($lien2==$lien):
     echo "same";
    else:
    echo "not same";
    endif;

    In result I’ve twice http://link.com and “not same”.

    Please explain me.

  • In your sample $lien contains the <br> in the string, whereas $lien2 only contains the link string and not the <br>.

    If you do this it should return true:

    
    $lien = get_field('fieldName');
    echo $lien.'<br/>';
    $lien2 = 'http://link.com';
    echo $lien2.'<br/>';
    if($lien2==$lien):
     echo "same";
    else:
    echo "not same";
    endif;
    
  • Yes sorry, <br> is a fail of copy past, I confirm I’ve

    $lien = get_field('fieldName');

    but it doesn’t works.

  • Ok, problem was with the option formatage, need to be in HTML to compare…

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Compare field with string’ is closed to new replies.