At least it does what it says in a logical way...



  • I was browsing some old, old code that I've once written and found this gem.

    Honestly, my code wasn't bad, I just didn't know that php had a builtin function for this. Luckily I don't support the code anymore.

    Damit, it sure is hard to plain show some code on this forum, i give up, look at the [url=http://mycomunicy.cvs.sourceforge.net/checkout/mycomunicy/main/lib/instr.php?revision=1.2]url[/url] instead.



  • No code? So it does ... nothing ... ?



  • @henke37 said:

    I was browsing some old, old code that I've once written and found this gem.

    Honestly, my code wasn't bad, I just didn't know that php had a builtin function for this. Luckily I don't support the code anymore.

    Damit, it sure is hard to plain show some code on this forum, i give up, look at the [url=http://mycomunicy.cvs.sourceforge.net/checkout/mycomunicy/main/lib/instr.php?revision=1.2]url[/url] instead.

    trying to put the code up myself.  See that wasn't so hard. 

    <?php
    function instr($a,$b) {
    for ($i;$i<strlen($a);++$i) {
    if (substr($a,$i,strlen($b))==$b) {
    //echo "ok";
    return true;
    }
    }
    return false;
    }
    //echo instr("abcdef","de");
    ?>



  • @henke37 said:

    Damit, it sure is hard to plain show some code on this forum, i give up

    I just paste the code normally, format a little, then go into the HTML dialog to replace the P with PRE 



  • @belgariontheking said:

    @henke37 said:

    I was browsing some old, old code that I've once written and found this gem. Honestly, my code wasn't bad, I just didn't know that php had a builtin function for this. Luckily I don't support the code anymore. Damit, it sure is hard to plain show some code on this forum, i give up, look at the [url=http://mycomunicy.cvs.sourceforge.net/checkout/mycomunicy/main/lib/instr.php?revision=1.2]url[/url] instead.

    trying to put the code up myself.  See that wasn't so hard. 

    <?php
    function instr($a,$b) {
    for ($i;$i<strlen($a);++$i) {
    if (substr($a,$i,strlen($b))==$b) {
    //echo "ok";
    return true;
    }
    }
    return false;
    }
    //echo instr("abcdef","de");
    ?>

    I don't get it...did you write the strlen and substr functions yourself also?



  • @savar said:

    @belgariontheking said:

    trying to put the code up myself.  See that wasn't so hard. 

    <?php
    function instr($a,$b) {
    for ($i;$i<strlen($a);++$i) {
    if (substr($a,$i,strlen($b))==$b) {
    //echo "ok";
    return true;
    }
    }
    return false;
    }
    //echo instr("abcdef","de");
    ?>

    I don't get it...did you write the strlen and substr functions yourself also?

    It's a strange kind of blindness while inventing that makes you forehead-slap yourself once you notice it. 



  • It even has a performance bug-- the loop needs only to go up to strlen(a) - strlen(b)



  • I tend more to the other extreme.  I say to myself, "There has GOT to be a pre-existing way to do this."  And then I wind up bending my data this way and that to shove it through existing routines.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.