Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

strpos Condition in question not working

More
1 month 1 week ago #274540 by preachie
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.17.0+260421 
Own server or LimeSurvey hosting: Own server
Survey theme/template: customized fruity
==================
Hey everyone,
I'm running out of ideas so I hope you can pinpoint me to the right direction.

I already reduced the testcase to a bare mininum.

I have a simple survey with one question group with two simple text questions.
Within the condition of the first question I'm using:

if(strpos("|0|2|", "|1|") > - 1, 1, 0)

so the question shouldn't be displayed. It's displayed anyways.
In the question text I added some debug lines:{if(strpos("|0|2|", "|1|") > - 1, 1, 0)}{if(strpos("|0|1|2|", "|1|") > - 1, 1, 0)}

With the expected result, that the first expression returns 0 and the second 1

I'm not sure if I'm doing something wrong or if it might be a bug, so I would be very thankful if someone would have any ideas :)

Thanks a lot
Mathias
 

Please Log in to join the conversation.

More
2 weeks 2 days ago - 2 weeks 2 days ago #274694 by Joffm
Hi,
the "strpos" function is a bit tricky in LimeSurvey.
Why?
The index starts at "0".
If the character is found on the very first place, the function returns O

BUT: if a character is not found, the function also returns 0.
Therefore your equation (">-1") is always true.
 
You can't solve this because LS does not support the operator "==="

I usually join a special character that the searched character is never the first, like
strpos(join("#","|0|2|"),"|1|")>0

Joffm

BTW: why this "if"?
and the whole function looks a bit complicated. why the "|"?

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 weeks 2 days ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose