# \[F\] $strstr(,needle) fails

**URL:** https://community.mp3tag.de/t/f-strstr-needle-fails/12251
**Category:** Fixed Bugs
**Tags:** bug-fixed
**Created:** [July 10, 2011, 12:50pm UTC](https://community.mp3tag.de/t/f-strstr-needle-fails/12251 "2011-07-10T12:50:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [July 10, 2011, 12:50pm UTC](https://community.mp3tag.de/t/f-strstr-needle-fails/12251/1 "2011-07-10T12:50:04Z")

</div>

$strstr(,needle) returns nothing, whereas I would expect it to return 0 as does $strstr(haystack,needle), given

Help  
$strstr(x,y) Finds the first occurrence of string y in string x.

Is this a known bug?

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [July 10, 2011, 3:28pm UTC](https://community.mp3tag.de/t/f-strstr-needle-fails/12251/2 "2011-07-10T15:28:12Z")

</div>

If I remember correctly from the good ole BASIC times the strstr-function (there called "instr") always produced a runtime error if the first string was empty or shorter than the second string. So one (the programmer) had to make sure that the function was let loose on a valid combination.  
Years if not decades have passed since ... apparently the function still requires a little common sense.

Which result would you have expected as IMHO checking "nothing" for the presence of a string should not produce the same result as finding that a string is definitely not part of another string? Something that can be expressed by a division by zero?

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [July 10, 2011, 4:56pm UTC](https://community.mp3tag.de/t/f-strstr-needle-fails/12251/3 "2011-07-10T16:56:51Z")

</div>

> [@chrisjj](#):
>
> ... Is this a known bug?

I am not sure, if it is a bug or a lack of information due to missing documentation.  
See yourself ...

**$strstr(x,y) liefert die Position an der die Zeichenkette y zum ersten Mal in x auftritt. $strstr('a')==\> nothing, because of Syntax Error? $strstr(,'a')==\> nothing, because of Syntax Error? $strstr('a',) ==\> nothing, because of Syntax Error? $strstr(,)==\> nothing, because of Syntax Error? $strstr()==\> nothing, because of Syntax Error? $strstr('','a')==\> 0 $strstr('a','')==\> 0 $strstr('','')==\> 1 $strstr('a''','')==\> 2 $strstr('a','a')==\> 1 $strstr(a,a)==\> 1 $strstr('ba','a')==\> 2 $strstr('a','ba') ==\> 0** 

 

DD.20110710.2058.CEST

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [July 10, 2011, 11:36pm UTC](https://community.mp3tag.de/t/f-strstr-needle-fails/12251/4 "2011-07-10T23:36:09Z")

</div>

> [@ohrenkino](#):
>
> ... apparently the function still requires a little common sense.

Your mean the function _definition_ requires a little common sense?

> [@ohrenkino](#):
>
> Which result would you have expected as IMHO checking "nothing" for the presence of a string should not produce the same result as finding that a string is definitely not part of another string?

It should. If the y is not in x, the result should be zero regardless of the value of x.

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [July 12, 2011, 12:02am UTC](https://community.mp3tag.de/t/f-strstr-needle-fails/12251/5 "2011-07-12T00:02:55Z")

</div>

Since this cannot be fixed in $strstr fixed without breaking script compatibility, can we please have a $strstr2 in which it is fixed?

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 28, 2018, 2:05pm UTC](https://community.mp3tag.de/t/f-strstr-needle-fails/12251/6 "2018-12-28T14:05:22Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
