s

PHP의 기본 str_replace 함수 보완 - 문자(열) 치환 완전 소거형식

· 2017-09-29 (금) 22:30:25 · 6482 · 2
<?php
header('Content-Type: text/html; charset=utf-8');

// str_lreplace 커스텀 함수의 (l)replace 소문자 '엘'은 Loop의 줄임말

function str_lreplace($find, $replace, $strings)
{
if ($strings && $find && $find!=$replace) {
if (stripos($replace, $find) !== false) {
$strings = str_ireplace($find, $replace, $strings);
}
else {
while(stripos($strings, $find) !== false) {
$strings = str_ireplace($find, $replace, $strings);
}
}
}
return $strings;
}


$test_str = '테스트 : testtesttestttesttestah!!testtesttesttesttesttesttesttttsseets 어지러워!';

$test_str_original = str_ireplace('testtest', 'test', $test_str);
$test_str_loop = str_lreplace('testtest', 'test', $test_str);

echo 'original text - '.$test_str;
echo '<br />';
echo 'str_ireplace - '.$test_str_original;
echo '<br />';
echo 'str_lreplace - '.$test_str_loop;
?>



[결과]
original text - 테스트 : testtesttestttesttestah!!testtesttesttesttesttesttesttttsseets 어지러워!
str_ireplace - 테스트 : testtestttestah!!testtesttesttesttttsseets 어지러워!
str_lreplace - 테스트 : testttestah!!testtttsseets 어지러워!
|

댓글 2개

오오 좋습니다.
좋아요..잘쓰겠습니다.감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

2,788건
+
제목 글쓴이 날짜 조회
17-11-05 조회 1.4만
17-11-05 조회 2만
17-11-03 조회 7,395
17-11-03 조회 8,406
17-11-03 조회 6,736
17-11-02 조회 8,126
17-11-01 조회 8,387
17-11-01 조회 5,386
17-11-01 조회 9,653
17-10-21 조회 8,858
17-10-21 조회 6,727
17-10-21 조회 1.5만
17-10-17 조회 6,325
17-10-16 조회 8,841
17-10-12 조회 6,701
17-10-12 조회 7,869
17-10-12 조회 8,308
17-10-10 조회 8,061
17-10-10 조회 9,002
17-10-08 조회 8,198
17-10-05 조회 6,483
17-10-04 조회 1.2만
17-10-02 조회 6,837
17-10-02 조회 6,467
17-10-01 조회 7,402
17-09-29 조회 6,483
17-09-29 조회 8,621
17-09-28 조회 8,056
17-09-27 조회 6,914
17-09-25 조회 6,507