Conditional based on a string containing another string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • westpointer
    Member
    • Mar 2004
    • 61

    Conditional based on a string containing another string

    I'm trying to write a conditional that compares two strings. If string one is contained in string 2, the conditional is true.

    string1 = 'cat'
    string2 = 'cat, dog, mouse'

    <if condition="$string2 == $string1">
    This is stuff only a cat member will see...
    </if>
    How can I modify the above code to be CONTAINS instead of IS?

    Thanks!
  • Jake Bunce
    Senior Member
    • Dec 2000
    • 46598
    • 3.6.x

    #2
    Unfortunately that requires string functions which are not allowed in template conditionals. The following functions are allowed in template conditional expressions:

    in_array() is_array() is_numeric() isset() empty() defined() array() can_moderate() can_moderate_calendar() exec_switch_bg() is_browser() is_member_of()

    The function you need is strstr().

    What exactly do you want to do? You might be able to use the phpinclude_start template for your application.

    Comment

    • KrisP
      Senior Member
      • Oct 2005
      • 237
      • 3.7.x

      #3
      I have same problem.

      I have a variable $referrer which is the url of the referring page.

      I want to make a conditional: if $referrer contains the string "xyz" then

      Comment

      • peterska2
        Senior Member
        • Oct 2003
        • 8869
        • 3.7.x

        #4
        Sorry, there is no function to do this. This requires modifying the code. We cannot officially support code modifications or forums running modified code, however you can try searching or asking for help with this over at www.vbulletin.org.

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...