Edit report at http://bugs.php.net/bug.php?id=53788&edit=1

 ID:                 53788
 Updated by:         ras...@php.net
 Reported by:        rzufall36 at yahoo dot com
 Summary:            Add in_string() function similar to in_array()
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
 Package:            Strings related
 Operating System:   Ubuntu 10.04
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Use strstr() or stristr()


Previous Comments:
------------------------------------------------------------------------
[2011-01-19 13:55:26] rzufall36 at yahoo dot com

Description:
------------
It would be quite helpful to have a helper function in_string(), like
in_array(), 

that checks if a substring is within some string. Sure, with
strpos()/stripos(), 

this can be achieved, but not everyone understands that immediately (and
the same 

could be said about in_array(), which can also be done quite simply with
a 

foreach, but surely not everyone gets that). There's some code how that
might 

work in PHP at MediaWiki 

http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/GlobalFunctions.p

hp?view=markup which is open-source and could be used.



Now it is the question if the third parameter should also be in PHP, but
no 

matter which way, it would still probably not too difficult to create
such a 

helper function.

Test script:
---------------
# MediaWiki's way of doing this



function in_string( $needle, $str, $insensitive = false ) {

    $func = 'strpos';

    if( $insensitive ) $func = 'stripos';

    return $func( $str, $needle ) !== false;

}



# don't use (bool)$func($str, $needle) because it can be 0 (first
character)



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53788&edit=1

Reply via email to