strpos misbehaving in script

Discuss and share scripts and script files...
Post Reply
MBaas
Posts: 572
Joined: 15 Feb 2016 21:08

strpos misbehaving in script

Post by MBaas »

I'm debugging a script that doesn't do what it is supposed to do and while doing so, I came across a surprising result from strpos that I can't understand - maybe I have a fundamental misunderstanding somewhere or maybe something else is wrong. I feel totally clueless atm and would appreciate another set of eyes (and braincells) looking at this.

I have added some logging and with that, the surprise comes from this code:

Code: Select all

                  $c1=-1
                  $c = strpos($currh,">",$c1);
                  $rep .= "strpos(" . quote($currh) . "," . quote(">")  . ",$c1)=$c<crlf>";
The variable $rep contains a log, and its value for the critical part is this:

Code: Select all

strpos("Apps>FinePrint",">",-1)=0
Yet, if I take exactly that code, prefix an echo and copy it into the address bar and execute it, it returns 4 - as expected.
So I added some more code to see if that really misbehaves as it seems to do:

Code: Select all

    $currh = "Apps>FinePrint";
    $c = strpos($currh,">",$c1);
    $rep = "strpos(" . quote($currh) . "," . quote(">")  . ",$c1)=$c<crlf>";
Nope, that gives the correct answer:

Code: Select all

strpos("Apps>FinePrint",">",-1)=4
So, could it be that the failing code "sees" different content than it prints? Don't know if that is even possible, but I would expected that in this case it would show a "surprising" strlen... Let's see:

Code: Select all

$rep .= "strpos(" . quote($currh) . "," . quote(">")  . ",$c1)=$c<crlf>strlen(currh)=" . strlen($currh) . <crlf>;
gave this:

Code: Select all

strpos("Apps>FinePrint",">",-1)=0
len(currh)=14
that seems to be correct. So I have no idea what else I could check and how I could sort out this problem...
______________________________________________
Happy user ;-)

autocart
Posts: 1243
Joined: 26 Sep 2013 15:22

Re: strpos misbehaving in script

Post by autocart »

MBaas wrote: 16 Oct 2021 17:02

Code: Select all

                  $c1=-1
                  $c = strpos($currh,">",$c1);
                  $rep .= "strpos(" . quote($currh) . "," . quote(">")  . ",$c1)=$c<crlf>";
I am not sure what the problem is exactly, but $c1=-1 certainly needs to be $c1=-1;.

MBaas
Posts: 572
Joined: 15 Feb 2016 21:08

Re: strpos misbehaving in script

Post by MBaas »

:oops: :oops: :oops:
Oh no...you're right. That fixes that - so I' can dig deeper now and see what else is going wrong.
:appl:

(But how embarrassing canit get? I've looked at that code and edited for hours - but I'm still not sufficiently fluent in XYlang to notice such ommissions! :oops: )
______________________________________________
Happy user ;-)

autocart
Posts: 1243
Joined: 26 Sep 2013 15:22

Re: strpos misbehaving in script

Post by autocart »

MBaas wrote: 16 Oct 2021 19:20 (But how embarrassing canit get? I've looked at that code and edited for hours - but I'm still not sufficiently fluent in XYlang to notice such ommissions! :oops: )
You ... are ... not ... alone ... :ninja: :biggrin:
Happens to me regularly.

Post Reply