 |
|
|  |
|
 |
11³â Àü |
¢º ¹®ÀÚ¿ ´Ùµë±â
- trim(), ltrim(), chop()¿¡¼ Áö¿ì´Â °ø¹éÀº ½ºÆäÀ̽º, '\n'(ÁٹٲÞ), '\t'(°¡·Î ÅÇ), '\v',
¡Û trim();
- ¹®ÀÚ¿ÀÇ Ã³À½°ú ³¡¿¡ ÀÖ´Â °ø¹éÀ» Áö¿î´Ù.
¡Û ltrim();
- ¹®ÀÚ¿ÀÇ Ã³À½¿¡ ÀÖ´Â °ø¹éÀ» Áö¿î´Ù.
¡Û chop();
- ¹®ÀÚ¿ÀÇ ³¡¿¡ ÀÖ´Â °ø¹éÀ» Áö¿î´Ù.
¢º ¹®ÀÚ¿ Á¤µ·
¡Û nl2br();
- ¹®ÀÚ¿Áß Áٹٲ޹®ÀÚ(\n)¸¦ XHTML¿¡¼ÀÇ ÁٹٲٱâÀÎ <br/>ű׷Π¹Ù²Ù¾î ÁØ´Ù.(4.0.5 ÀÌÀüÀÇ HTML¿¡¼´Â <br>ű×)
¢º ¹®ÀÚ¿ÀÇ ´ë¼Ò¹®ÀÚ °ü·Ã ÇÔ¼ö
¡Û strtoupper();
- ¸ðµç ¾ËÆĺªÀ» ´ë¹®ÀÚ·Î
¡Û strtolower();
- ¸ðµç ¾ËÆĺªÀ» ¼Ò¹®ÀÚ·Î
¡Û ucfirst();
- ¹®ÀåÀÇ Ã³À½ÀÌ ¾ËÆĺªÀÌ¸é ±×°Í¸¸ ´ë¹®ÀÚ·Î
¡Û ucword();
- °¢ ´Ü¾îÀÇ Ã¹ ¾ËÆĺªÀ» ´ë¹®ÀÚ·Î
¢º ¹®ÀÚ¿ ³ª´©°í ÇÕÄ¡±â
¡Û explode();
- ÁöÁ¤ ¹®ÀÚ¸¦ ±âÁØÀ¸·Î ¹®ÀÚ¿ÀÇ Àü, Èĸ¦ ³ª´©¾î ¹è¿·Î ÀúÀåÇÑ´Ù.
ex) $email = 'email@email.com'; $email_array = explode('@', $email);
$email_array[0] ¡æ 'email'; $email_array[1] ¡æ 'email.com';
¡Û implode();, join();
- ÁöÁ¤ ¹®ÀÚ¸¦ ±âÁØÀ¸·Î ¹è¿À» Àü, ÈÄ¿¡ ¹èÄ¡ÇÏ¿© ¹®ÀÚ¿À» ÇÕÄ£´Ù.
ex) $new_email = implode('@', email_array); $new_email ¡æ 'email@email.com';
¡Û strtok();
- ÁöÁ¤ ÅäÅ«¹®ÀÚ·Î ÅäÅ«È Çؼ ±¸ºÐ
ex)
$token = strtok($feedbak, ' ') // óÀ½ ÅäÅ«È Çϱâ
echo $token.'<br />';
while ($token!= ''){
$token = strtok(' '); // µÎ¹ø° ÅäÅ«È (ÅäÅ«ÈÇÏ°í ½ÍÀº)
echo $token.'<br />';
}
¡Û substr();
- ¹®ÀÚ¿ Áß Æ¯Á¤ ½ÃÀۺκаú ³¡ºÎºÐ »çÀÌÀÇ ¹®ÀÚ¿À» ÃßÃâÇϴµ¥ »ç¿ëÇÑ´Ù.
ex) $test = 'PHP Webprogramming';
$test1 = substr($test, 1); $test2 = substr($test, -1); $test3 = substr($test, 5, 8); $test4 = substr($test, 4, -2);
$test1 ¡æ 'HP Webprogramming'(¾Õ¿¡¼ 1¹ø ºÎÅÍ)
$test2 ¡æ 'g'(µÚ¿¡¼ 1¹ø ºÎÅÍ)
$test3 ¡æ 'ebprogra'(¾Õ¿¡¼ 5¹øºÎÅÍ 8°³)
$test4 ¡æ 'Webprogrammi'(¾Õ¿¡¼ 4¹øºÎÅÍ µÚ¿¡¼ 2¹ø±îÁö)
¢º ¹®ÀÚ¿ ºñ±³Çϱâ
¡Û strcmp();
- C¾ð¾î¿¡¼ÀÇ ÇÔ¼ö¿Í °°´Ù. ¾ÕÀÇ ¹®ÀÚ¿À» ±âÁØÀ¸·Î °°À¸¸é 0À», ¿ì¼±¼øÀ§°¡ ³ôÀ¸¸é -1À», ¹Ý´ëÀÇ °æ¿ì¿¡´Â 1À» ¸®ÅÏÇÑ´Ù.
- ´Ü, ´ë¹®ÀÚ¿Í ¼Ò¹®ÀÚÀÇ °æ¿ì ¼Ò¹®ÀÚ°¡ ¿ì¼±¼øÀ§°¡ ´õ ³ô´Ù.(ASCIIÄÚµåÀÇ ´ë¼Ò°ü°è¸¦ »ý°¢ÇÏ¸é ½±´Ù.)
¡Û strcasecmp();
- C¾ð¾î¿¡¼ÀÇ stricmp()¿Í °°´Ù. µÎ ¹®ÀÚ¿À» ºñ±³ÇÏ´Â °ÍÀº strcmp()¿Í °°Áö¸¸ ´ë¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÏÁö ¾Ê´Â´Ù.
¡Û strnatcmp(); & strnatcasecmp();
- ÀÌ µÎ ÇÔ¼ö´Â ¹®ÀÚ¿À» Á»´õ ÀÚ¿¬½º·¯¿î ±âÁØ¿¡¼ ºñ±³ÇÑ´Ù.(strnatcmp("12","2")ÀÇ °á°ú´Â 1ÀÌ´Ù.)
- ÀÌ µÎ ÇÔ¼öÀÇ Â÷ÀÌ´Â ´ë¼Ò¹®ÀÚÀÇ ±¸ºÐ¿©ºÎÀÌ´Ù.(ÀÌ µÎ ÇÔ¼öÀÇ Â÷ÀÌ´Â caseÀÇ À¯¹«¿©ºÎÀÌ´Ù.)
¢º ¹®ÀÚ¿ÀÇ ±æÀÌ È®ÀÎÇϱâ
¡Û strlen();
- C¾ð¾î¿¡¼ÀÇ ÇÔ¼ö¿Í °°´Ù. ¹®ÀÚ¿ÀÇ ±æÀ̸¦ Á¤¼ö°ªÀ¸·Î ¸®ÅÏÇØÁØ´Ù.
¢º ¹®ÀÚ¿ ¾È¿¡¼ ¹®ÀÚ¿ ã±â
¡Û strstr();
- ¹®ÀÚ¿ ¾È¿¡¼ ƯÁ¤ ¹®ÀÚ¿°ú ÀÏÄ¡ÇÏ´Â ºÎºÐÀÌ ÀÖ´ÂÁö ã¾Æ³»´Âµ¥ ¾²ÀÌ´Â ÇÔ¼öÀÌ´Ù.
- ÀÏÄ¡ÇÏ´Â ¹®ÀÚ¿ÀÌ ÀÖÀ» ¶§´Â ÇØ´ç ¹®ÀÚ¿À̳ª ¹®ÀÚ¸¦ Æ÷ÇÔÇÏ¿© ÀÌÈÄ ¹®ÀÚ¿À» ¸®ÅÏÇÑ´Ù.
- ÀÏÄ¡ÇÏ´Â ¹®ÀÚ¿ÀÌ ¾øÀ» ½Ã¿¡´Â false¸¦ ¸®ÅÏÇÑ´Ù.
ex) $str='Lion sleep to night'; $res = strstr($str, 'sleep');
$res ¡æ 'sleep to night'
¡Û stristr();
- strstr()°ú °°À¸³ª ´ë¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÏÁö ¾Ê´Â´Ù.(ABC, Abc, aBC¸ðµÎ °°Àº °ÍÀ¸·Î Ãë±ÞÇÑ´Ù.)
¡Û strchr();
- strstr()°ú °°À¸³ª ¹®ÀÚ¿´ë½Å ¹®ÀÚ¸¦ ã´Â´Ù.
¡Û strrch();
- strchr()°ú °°À¸³ª µÚ¿¡¼ ºÎÅÍ ÀÏÄ¡ÇÏ´Â ¹®ÀÚ¸¦ ã±â ¶§¹®¿¡ ¸¶Áö¸·À¸·Î ³ªÅ¸³ ¹®ÀÚºÎÅÍ ¹®ÀÚ¿À» Ãâ·ÂÇÑ´Ù.
¢º ¹®ÀÚ¿ÀÇ À§Ä¡ ã¾Æ³»±â
¡Û strpos();
- ¹®ÀÚ¿ ³»¿¡¼ ÀÏÄ¡ÇÏ´Â ¹®ÀÚ¿À̳ª ¹®ÀÚ¸¦ ã¾Æ ¹®ÀÚ¿ ´ë½Å ÇØ´ç À§Ä¡¸¦ ¼ýÀÚ·Î ¾Ë·ÁÁØ´Ù.
ex) $test = 'Ice cream'; $res1 = strpos($test, 'a'); $res2 = strpos($test, 'e');
$res1 ¡æ 7(0ºÎÅÍ ½ÃÀÛÇÑ´Ù.) $res2 = 2(ÀÏÄ¡ÇÏ´Â ¹®ÀÚ³ª ¹®ÀÚ¿ÀÌ ¸¹À» °æ¿ì °¡Àå ¾ÕÀÇ °ÍÀ» ±âÁØÀ¸·Î ÇÑ´Ù.)
ex) $test = 'Ice cream'; $res = strpos($test, 'e', 4);
$res = 6(¾Õ¿¡¼ºÎÅÍ 4¹ø°¿¡ ÀÖ´Â cºÎÅÍ ÇØ´ç¹®ÀÚ¿ÀÇ À§Ä¡¸¦ ã´Â´Ù.)
¡Û strrpos();
- strpos¿Í ºñ½ÁÇϳª ã´Â ¹®ÀÚ°¡ °¡Àå ¸¶Áö¸·¿¡ º¸ÀÌ´Â °÷ÀÇ À§Ä¡¸¦ ¸®ÅÏÇÑ´Ù.
¡Ø µÎ ÇÔ¼ö ¸ðµÎ ¸¸¾à ¹®ÀÚ¿¿¡ needle(ã´Â ¹®ÀÚ³ª ¹®ÀÚ¿)ÀÌ ¾øÀ¸¸é false¸¦ ¸®ÅÏÇϴµ¥ PHP¿¡¼´Â false¸¦ 0°ú °°´Ù°í º¸±â ¶§¹®¿¡
À§Ä¡ 0À» ¸®ÅÏÇÑ°ÍÀÎÁö false¸¦ ¸®ÅÏÇÑ °ÍÀÎÁö ±¸ºÐÇÒ ¼ö°¡ ¾ø´Ù. ÀÌ ¹®Á¦´Â === ¿¬»êÀÚ¸¦ »ç¿ëÇÏ¿© ÇØ°áÇÒ ¼ö ÀÖ´Ù.
ex) $res = strpos('Hello world', 'H'); //ÀÌ °æ¿ì¿¡´Â °¡Àå ¾Õ¿¡ 'H'°¡ Àֱ⠶§¹®¿¡ 0À» ¸®ÅÏÇÏÁö¸¸ PHP´Â false¿Í ±¸ºÐÇÏÁö ¸øÇÑ´Ù.
if($res === false)
echo 'Not found';
else
echo 'Found at position 0';
¢º ¹®ÀÚ¿ ´ëüÇϱâ
¡Û str_replace();
- ¹®ÀÚ¿¿¡¼ ¹®ÀÚ¿¸¦ ã¾Æ ´ëü¹®ÀÚ¿·Î ¹Ù²Ù¾î ¸®ÅÏÇÑ´Ù.
ex) $test = 'Change'; $res = str_replace('g', 'c', $test);
$res ¡æ 'Chance'
¡Û substr_replace();
- ƯÁ¤ À§Ä¡ÀÇ ¹®ÀÚ¿À» ´ëü¹®ÀÚ¿·Î ¹Ù²Ù¾î ¸®ÅÏÇÑ´Ù.
ex) $test = 'Vitamin A'; $res = substr_replace($test, 'C', -1);
$res ¡æ 'vitamin C'
|
|
̵̧ : 538 |
̵̧
¸ñ·Ï
|
|
|  |
|