sscanf

(PHP 4 >= 4.0.1)

sscanf -- 포멧이 따라서 입력을 문자열로부터 파싱한다.

설명

mixed sscanf ( string str, string format [, string var1])

sscanf() 함수는 printf()의 입력 유사성을 가진다. sscanf()sms str 문자열로 부터 입력을 읽어 특정한 format 에 따라 인터럽트한다. - sscanf() reads from the string str and interprets it according to the specified format. 만약 두개의 매개변수만이 이 함수로 전달된다면, 파싱된 값은 배열로서 반환된다.

예 1. sscanf()

// 시리얼 번호를 얻는다.

$serial = sscanf("SN/2350001","SN/%d");

// 제조일을 지정한다.

$mandate = "January 01 2000";

list($month, $day, $year) = sscanf($mandate,"%s %d %d");

echo "Item $serial was manufactured on: $year-".substr($month,0,3)."-$day\n";
선택적인 매개변수가 전달되면, 함수는 할당된 값에 대한 수를 반환한다. 선택적인 매개변수는 반드시 참조에 의해 전달되어야 한다.

예 2. sscanf() - 선택적인 매개변수 사용하기

// 작가 정보를 얻고 DocBook의 인트리를 활성화한다.

$auth = "24\tLewis Carroll";

$n = sscanf($auth,"%d\t%s %s", &$id, &$first, &$last);

echo "<author id='$id'>

	<firstname>$first</firstname>

	<surname>$last</surname>

</author>\n";

fscanf(), printf(), 그리고 sprintf()를 참고하라.