HTML2011. 5. 10. 08:11

1. strpos()함수 //stripos()는 대소문자를 구분하지 않습니다. )

int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
haystack

The string to search in

needle

If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.

offset

The optional offset parameter allows you to specify which character in haystack to start searching. The position returned is still relative to the beginning of haystack.

 
$haystack 문자열에 찾고자 하는 $needle 문자가 있으면 그 위치를 리턴한다.
만약 없다면 false 리턴.
 
$offset은 찾는 위치를 지정. 2로 지정한다면 #hastack 문자열의 2번째 위치부터 검색한다.
 
ex) if( strpos($domain,'.')===false ) return false;
 
 
2. strrpos() 문자열에서 마지막 문자의 위치를 찾습니다. (strripos()는 대소문자를 구분하지 않습니다.)
 
int strrpos ( string $haystack , string $needle [, int $offset ] )
 

haystack 문자열에서 마지막으로 나오는 needle 의 위치를 수로 반환합니다. PHP 4에서 needle은 하나의 문자만 사용할 수 있습니다. 문자열을 needle로 전달하면, 문자열의 첫번째 문자만을 사용합니다.

needle 이 발견되지 않으면, FALSE를 반환합니다.

 

3. string strrchr ( string $haystack , mixed $needle )

이 함수는 needle 가 마지막으로 나오는 위치부터 haystack 의 마지막까지의 haystack 문자열 부분을 반환합니다.

반환값이 없으면 false 리턴.

 

4. string strstr ( string $haystack , mixed $needle [, bool $before_needle ] )

needle 에서 haystack 이 처음 발견된 곳부터 끝까지의 부분 문자열을 반환합니다.

반환값 없으면 false 리턴.

 

5.string substr ( string $string , int $start [, int $length ] )

Returns the portion of string specified by the start and length parameters.

ex) substr("abcdef", -1);    // returns "f"
     substr("abcdef"2, -1);  // returns "cde"
     substr('abcdef'1);     // bcdef

Posted by 아이맥스