ȨÀ¸·Î | ¹«·áȸ¿ø°¡ÀÔ | ¾ÆÀ̵ð/ºñ¹øÃ£±â
ÃßõÀ½¾Ç¹æ¼Û
ereg replace
11³â Àü
(PHP 3, PHP 4 , PHP 5)

ereg_replace -- Replace regular expression
Description
string ereg_replace ( string pattern, string replacement, string string)


This function scans string for matches to pattern, then replaces the matched text with replacement.

The modified string is returned. (Which may mean that the original string is returned if there are no matches to be replaced.)

If pattern contains parenthesized substrings, replacement may contain substrings of the form \\digit, which will be replaced by the text matching the digit'th parenthesized substring; \\0 will produce the entire contents of string. Up to nine substrings may be used. Parentheses may be nested, in which case they are counted by the opening parenthesis.

If no matches are found in string, then string will be returned unchanged.

For example, the following code snippet prints "This was a test" three times:

¿¹ 1. ereg_replace() example

<?php

$string = "This is a test";
echo str_replace(" is", " was", $string);
echo ereg_replace("( )is", "\\1was", $string);
echo ereg_replace("(( )is)", "\\2was", $string);

?>  



One thing to take note of is that if you use an integer value as the replacement parameter, you may not get the results you expect. This is because ereg_replace() will interpret the number as the ordinal value of a character, and apply that. For instance:

¿¹ 2. ereg_replace() example

<?php
/* This will not work as expected. */
$num = 4;
$string = "This string has four words.";
$string = ereg_replace('four', $num, $string);
echo $string;   /* Output: 'This string has   words.' */

/* This will work. */
$num = '4';
$string = "This string has four words.";
$string = ereg_replace('four', $num, $string);
echo $string;   /* Output: 'This string has 4 words.' */
?>  



¿¹ 3. Replace URLs with links

<?php
$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
                     "<a href=\"\\0\">\\0</a>", $text);
?>  



ÀÛÀº Á¤º¸: preg_replace(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to ereg_replace().
ÃßõÃßõ : 186 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
3,030
 Á¦ÀÌÄõ¸® ±âº» ¸í·É¾î
3,029
 À¥ÆäÀÌÁö °¡·Î ¸ðµå¼¼·Î ¸ðµå ÀνÄÇϱâ
3,028
 ¸ð¹ÙÀÏ À¥ È­¸é °­Á¦ ȸÀü(°¡·Î¸ðµå °íÁ¤)
3,027
 [HTML5]¿¡¼­ frameset ´ëü ¹æ¹ý°ú iframe ¼Ó¼º
3,026
 HTML <Audio> »ç¿ë¹ý
3,025
 À©µµ¿ì10 ½Ã½ºÅÛÆÄÀÏ ¼Õ»ó (Ãʰ£´Ü ¿À·ù º¹±¸¹æ¹ý!!)
3,024
 PHP ÆÄÀÏ Á¸Àç ¿©ºÎ ÆÄ¾ÇÇϱâ(·ÎÄà ÆÄÀÏ Á¸Àç ¹× ¿ø°ÝÁö ÆÄÀÏ Á¸Àç)
3,023
 [CSS] ¹Ú½º ¼¼·Î °¡¿îµ¥ Áß¾Ó Á¤·Ä 6°¡Áö
3,022
 CSS Layout ¼öÆò & ¼öÁ÷ Á¤·Ä
3,021
 ¿©·¯ µµ¸ÞÀÎµé °£ ÄíŰ °øÀ¯Çϱâ
3,020
 ÅÂ±× »çÀÌ¿¡ ÀÖ´Â ÅØ½ºÆ®¸¦ ÃßÃâ
3,019
 [JQuery] textbox focus on offÀ϶§ ¼ýÀÚ ÄÞ¸¶ º¸¿©ÁÖ±â
3,018
 ÄíŰ »ý¼º,°¡Á®¿À±â,»èÁ¦
3,017
 »ç¿ëÀÚ ÇÔ¼ö ¸ðÀ½
3,016
 ¸¶¿ì½º,Űº¸µå Á¦ÇÑ ( ¿À¸¥ÂÊŬ¸¯,µå·¡±×,¿µ¿ª¼±Åõî..)
3,015
 [HTML5] <video> - DOMÀ¸·Î Á¦¾îÇϱâ
3,014
 HTML5 video ű׿¡¼­ ¿µ»ó Á¿ì¹ÝÀü
3,013
 PHP - ƯÁ¤ ÅÂ±× ¹× ¹®ÀÚ¿­ ÃßÃâ, Á¦°Å
3,012
 [PHP] define°ú definedÀÇ Â÷ÀÌ
3,011
 ¿ìŬ¸¯ ¿Ïº®Â÷´Ü ½ºÅ©¸³Æ®
3,010
 iframe ³ôÀÌ 100% ¸ÂÃß±â
3,009
 curl ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ HTTP REFERER º¯°æ
3,008
 À©µµ¿ì10 ½Ã½ºÅÛ ÆÄÀÏ ¹× Dism °Ë»ç
3,007
 ÅؽºÆ® ÁٹٲÞ, ±ÛÀÚÀÚ¸£±â CSS
3,006
 jQuery Mobile¿¡¼­ À¯¿ëÇÑ ÄÚµå 10°¡Áö.
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æÄ§
Copyright (C) musictrot All rights reserved.