From:             
Operating system: Ubuntu 10.04
PHP version:      Irrelevant
Package:          Strings related
Bug Type:         Feature/Change Request
Bug description:Add in_string() function similar to in_array()

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 bug report at http://bugs.php.net/bug.php?id=53788&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53788&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53788&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53788&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53788&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53788&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53788&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53788&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53788&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53788&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53788&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53788&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53788&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53788&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53788&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53788&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53788&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53788&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53788&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53788&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53788&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53788&r=mysqlcfg

Reply via email to