Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

strpbrk

(PHP 5)

strpbrk --  Ищет в строке любой символ из заданного набора

Описание

string strpbrk ( string haystack, string char_list )

strpbrk() ищет в строке haystack символы из набора char_list и возвращает строку начиная с той позиции, где был найден символ (или FALSE если символ не найден).

Замечание: Параметр char_list чувствителен к регистру.

Пример 1. Пример использования функции strpbrk()

<?php

$text
= 'This is a Simple text.';

// Этот код выдаст "is is a Simple text.", т.к. символ 'i' встретится раньше
echo strpbrk($text, 'mi');

// Этот код выдаст "Simple text.", т.к. символы чувствительны к регистру
echo strpbrk($text, 'S');
?>



strpos> <strncmp
Last updated: Sat, 27 Jan 2007
 
add a note add a note User Contributed Notes
strpbrk
pzb at novell dot com
28-Jul-2007 04:09
One undocumented requirement:
If $char_list contains null characters ("\0"), only characters before the null will be used.  While PHP handles nulls in strings just fine, the data is passed to a function that is not null safe.
Evan
03-Jul-2007 08:33
If you're not looking to duplicate the rest of the string, but instead just want the offset, in the spirit of the str*pos() functions:

<?php

function strpbrkpos($s, $accept) {
 
$r = FALSE;
 
$t = 0;
 
$i = 0;
 
$accept_l = strlen($accept);

  for ( ;
$i < $accept_l ; $i++ )
    if ( (
$t = strpos($s, $accept{$i})) !== FALSE )
      if ( (
$r === FALSE) || ($t < $r) )
       
$r = $t;

  return
$v;
}

?>
user at example dot net
03-Jul-2007 12:25
For PHP versions before 5:

<?php

   
function strpbrk( $haystack, $char_list )
    {
       
$strlen = strlen($char_list);
       
$found = false;
        for(
$i=0; $i<$strlen; $i++ ) {
            if( (
$tmp = strpos($haystack, $char_list{$i})) !== false ) {
                if( !
$found ) {
                   
$pos = $tmp;
                   
$found = true;
                    continue;
                }
               
$pos = min($pos, $tmp);
            }
        }
        if( !
$found ) {
            return
false;
        }
        return
substr($haystack, $pos);
    }

?>

Sadly this is about ten times slower than the native implementation.
jamie dot mcardle at stpetersgv dot org
07-Jun-2007 02:54
I wanted to use this function to look for an @ in a db entry - didn't work because I don't have this version of PHP yet, but I thought I had my issue licked. Darn it.
aidan at php dot net
21-Aug-2004 01:11
This functionality is now implemented in the PEAR package PHP_Compat.

More information about using this function without upgrading your version of PHP can be found on the below link:

http://pear.php.net/package/PHP_Compat

strpos> <strncmp
Last updated: Sat, 27 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571