Skip to content

Instantly share code, notes, and snippets.

@erikreagan
Created November 18, 2009 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikreagan/237491 to your computer and use it in GitHub Desktop.
Save erikreagan/237491 to your computer and use it in GitHub Desktop.
<?php
// The function strlen() returns the interger value of the string length within the parentheses
// We can string multiple together with math operators for equations
// PHP enabled in template
// Parsing Stage: Output
// Simple conditional here
// We group the strlen values in parentheses to get their value
// and compare to the following integer (10 in the example)
// Basic example
if ((strlen("{custom_field_1}") + strlen("{custom_field_2}")) > 10)
{
// whatever your code requires
}
// Alternate syntax
if ((strlen("{custom_field_1}") + strlen("{custom_field_2}")) > 10) :
// whatever your code requires
endif;
?>
<p>Here's how I would use it in a template:</p>
<?php if ((strlen("{custom_field_1}") + strlen("{custom_field_2}")) > 100) : ?>
This shows up because the combined length of {custom_field_1} and {custom_field_2} is greater than 100.
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment