Detail Page - check List needs to show image

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 2, 2014   (RSS)

By Chris - April 2, 2014

strpos() returns FALSE if the "needle" isn't found in the "haystack". If it is found, it returns the character position of the start of the first match. Note that it can return 0 if the needle is found at the very start of the haystack. For example:

var_export(strpos("haystack haystack haystack NEEDLE haystack", "NEEDLE")); // outputs "27"
var_export(strpos("NEEDLE haystack haystack haystack haystack", "NEEDLE")); // outputs "0"
var_export(strpos("haystack haystack haystack haystack", "NEEDLE"));        // outputs "false"

Because 0 can seem like FALSE to PHP, to check if a string contains another string, it's important to use a strict equality test to check for FALSE:

var_export(strpos("haystack haystack haystack NEEDLE haystack", "NEEDLE") !== FALSE); // outputs "true"
var_export(strpos("NEEDLE haystack haystack haystack haystack", "NEEDLE") !== FALSE); // outputs "true"
var_export(strpos("haystack haystack haystack haystack", "NEEDLE") !== FALSE);        // outputs "false"

Alternately, if you're using CMS Builder version 2.50 or newer, you can use the contains() function, but note well that the order of the needle and haystack arguments are flipped:

var_export(contains("NEEDLE", "haystack haystack haystack NEEDLE haystack")); // outputs "true"
var_export(contains("NEEDLE", "NEEDLE haystack haystack haystack haystack")); // outputs "true"
var_export(contains("NEEDLE", "haystack haystack haystack haystack"));        // outputs "false"

Does this work for you?

<?php if (contains("\tWarm\t", $productsRecord['type'])) : ?>
  <img src="http://comfy.exedor.us/images/warm1.gif" border="0" width="47" height="47" ></a>
<?php endif; ?>

<?php if (contains("\tSmell\t", $productsRecord['type'])) : ?>
  <img src="http://comfy.exedor.us/images/smell1.gif" border="0" width="47" height="47" ></a>
<?php endif; ?>

<?php if (contains("\tCool\t", $productsRecord['type'])) : ?>
  <img src="http://comfy.exedor.us/images/cold1.gif" border="0" width="47" height="47" ></a>
<?php endif; ?>

All the best,
Chris

By thenetgirl - April 2, 2014

Thanks so much Chris it works :-)

Patricia

www.thenetgirl.com