
mb_ereg_replace_callback 함수는 preg_replace_callback 함수와 유사하게 작동합니다.
치환할 문자열과 치환될 문자열을 지정하려면 callback 함수를 사용하세요.
callback 함수는 치환할 문자열을 매개변수로 받고, 치환될 문자열을 반환합니다.
예를 들어, "hello world" 문자열에서 "world"를 "php"로 치환하고 싶다면, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$text = "hello world";
$pattern = "/world/";
$replacement = "php";
$result = mb_ereg_replace_callback($pattern, function($match) {
return $replacement;
}, $text);
echo $result; // hello php
또는 callback 함수를 사용할 수 있습니다.
#hostingforum.kr
php
$text = "hello world";
$pattern = "/world/";
$result = mb_ereg_replace_callback($pattern, function($match) {
return "php";
}, $text);
echo $result; // hello php
이러한 방법으로 mb_ereg_replace_callback 함수를 사용하여 특정 문자열을 치환할 수 있습니다.
2025-07-05 10:54