PHP String Functions

Examples 2008. 1. 21. 12:27

PHP에는 문자열을 다루기 위한 많은 함수들이 존재한다.

문자열의 길이를 알기 위해 다음과 같이 할 수 있다.

<?php

$str = "Hello world!";

$len = strlen($str);

echo "<P>Length: " . $len . "</P>";

?>

문자열 내에서 특정 문자 혹은 문자열의 위치를 알기 위해 다음과 같이 할 수 있다.

<?php

$str = "Hello world!";
$lookFor = "world";

$pos = strpos($str, $lookFor);

echo "<P>Position: " . $pos . "</P>";

?>

Reference:
http://www.w3schools.com/php/php_string.asp
http://www.w3schools.com/php/php_ref_string.asp

Posted by 알 수 없는 사용자
,