Hello, I want to compare two strings and show a message if they are different or not, I'm using the strcmp function (in a custom HTML box) but it seems not to work, here is the code:
<?php
$str1 = "{var:read_data.tblx.FirtField}";
$str2 = "{var:read_data.tlby.SecondField}";
echo strcmp($str1, $str2); // if it work in here I'll add the IF THEN condition
?>
The result is always -10 wherever the two fields are identical or not, I've tried to echo both $str1 and $str2 just to be sure they are read correctly and they are, if I change to:
<?php
$str1 = "a";
$str2 = "a";
echo strcmp($str1, $str2);
?>
I got 0 as result (and any other result if I change the strings), where I'm wrong?
<?php
$str1 = "{var:read_data.tblx.FirtField}";
$str2 = "{var:read_data.tlby.SecondField}";
echo strcmp($str1, $str2); // if it work in here I'll add the IF THEN condition
?>
The result is always -10 wherever the two fields are identical or not, I've tried to echo both $str1 and $str2 just to be sure they are read correctly and they are, if I change to:
<?php
$str1 = "a";
$str2 = "a";
echo strcmp($str1, $str2);
?>
I got 0 as result (and any other result if I change the strings), where I'm wrong?
you better use the if conditions directly and use if == or !=
if you want to use PHP then you need to call the variables like this:
if you want to use PHP then you need to call the variables like this:
$this->get("read_data.tblx.FirstField")
Thanks Max, the PHP variable call works fine. I post my code just in case it could be useful to someone.
<?php
$str1 = $this->get("read_data.tblone.FirstField");
$str2 = $this->get("read_data.tbltwo.SecondField");
if (strcmp($str1, $str2)== "0") {
echo "<i class=\"thumbs up icon green big\"></i>";
} else {
echo "<i class=\"hand paper icon red big\"></i>";
}
?>
<?php
$str1 = $this->get("read_data.tblone.FirstField");
$str2 = $this->get("read_data.tbltwo.SecondField");
if (strcmp($str1, $str2)== "0") {
echo "<i class=\"thumbs up icon green big\"></i>";
} else {
echo "<i class=\"hand paper icon red big\"></i>";
}
?>
This topic is locked and no more replies can be posted.