JavaScript or jQuery equivalent of PHP’s strstr() function

Try using this: function strstr(haystack, needle, bool) { // Finds first occurrence of a string within another // // version: 1103.1210 // discuss at: http://phpjs.org/functions/strstr // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Onno Marsman // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: strstr(‘Kevin van Zonneveld’, ‘van’); … Read more

strstr not functioning

It’s because fgets stores the newline character so when strstr does a comparison it fails. From the man page: fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it … Read more