Á¤±ÔÇ¥Çö½Ä °Ë»ç µµ±¸ (ereg, eregi) |
|
|
 |
14³â Àü |
Á¤±ÔÇ¥Çö½Ä(Regular expression)À̶õ ¾î¶°ÇÑ °ªÀÌ Æ¯Á¤ÇÑ ÇüŸ¦ °®´ÂÁö¸¦ °Ë»çÇÏ´Â µµ±¸·Î¼
ereg´Â ¹®ÀÚ¿¿¡ ¾î¶² ¹®ÀÚ°¡ Æ÷ÇÔ µÇ¾î Àִ°¡¸¦ °Ë»çÇÏ´Â ÇÔ¼ö·Î
ÀúÀåµÉº¯¼ö = ereg ("°Ë»çÇÒ ¹®ÀÚ", "°Ë»ç´ë»ó ¹®ÀÚ¿")
"°Ë»ç´ë»ó ¹®ÀÚ¿"¿¡ "°Ë»çÇÒ ¹®ÀÚ"°¡ Æ÷ÇԵǾî ÀÖ´ÂÁö¸¦ °Ë»çÈÆ ÈÄ¿¡, Æ÷ÇԵǾî ÀÖ´Ù¸é TRUE¸¦,
Æ÷ÇԵǾî ÀÖÁö ¾Ê´Ù¸é FALSE¸¦ ¸®ÅÏÇÕ´Ï´Ù.
ereg ÇÔ¼ö´Â ¿µ¾îÀÇ ´ë¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÏÁö¸¸, eregi ÇÔ¼ö´Â ´ë¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÏÁö ¾Ê½À´Ï´Ù.
¢Ã À̸ÞÀÏ ÁÖ¼Ò¿Í È¨ÆäÀÌÁö ÁÖ¼Ò Ã¼Å©Çϱâ
<?
/*-- À̸ÞÀÏ ÁÖ¼Ò Ã¼Å©Çϱâ --*/
$a=primato@naver.com;
$ex="^[-_a-z0-9]+(\.[-_a-z0-9]+)*@[-a-z0-9]+(\.[-a-z0-9]+)+$";
echo eregi($ex, $a);
/*-- ȨÆäÀÌÁö ÁÖ¼Ò Ã¼Å©Çϱâ --*/
$b="http://phpboy.hosting.paran.com";
$hx="^http://[-a-z0-9]+(\.[-a-z0-9]+)*(/[^\\\/:\*\"<>\|]+(\.[^\\\/:\*\"<>\|]+)*)*/?$";
echo eregi($hx, $b);
/*-- eregi ÇÔ¼ö´Â ´ë¼Ò¹®ÀÚ¸¦ ±¸º°ÇÏÁö ¾Ê´Â´Ù-- */
?>
http://docs.php.net/manual/kr/function.eregi.php |
|
̵̧ : 296 |
̵̧
¸ñ·Ï
|
|