EllisLab text mark
Advanced Search
     
Match segment to (last) part of a string?
Posted: 07 February 2010 05:52 PM
Joined: 2009-07-18
38 posts

Hi There-

I’ve been trying all sorts of things over the last few weeks trying to solve this issue.

I want to match a segment (say, segment_2) to the last part of a string that’s formatted like this: /one/two/three/

Here’s what I would like to accomplish in non-working code:

{if {segment_2} == last part of string "/one/two/three/") class="yellow" {/if} 

The last part of string “/one/two/three/”  obviously needs to be replaced with some good code.

I’ve tried the phpfunstring plugin, but couldn’t get the ‘explode’ function to work.  Got an error message that the string was converted into an array. Couldn’t solve that.

I tried the stristr function, and got it to work… halfway.  i can’t seem to test the result against a segment.  I can get it to match the string, but I can’t check to see if it matches a segment.

I tried: (template name is ‘string’)

{{if "{segment_2}" == "{exp:phpstringfun function="stristr" par1="{segment_2}" } /one/two/string/ {/exp:phpstringfun}}" boo{/if} 

PHP error.

Any ideas?  Is ther another way I can match this?

Kind of lost.

Thanks!