str_ireplace를 원래 케이스를 손상시키지 않고 실행할 수 있습니까? 예컨대PHP str_ireplace 케이스를 잃지 않고
:
$txt = "Hello How Are You";
$a = "are";
$h = "hello";
$txt = str_ireplace($a, "<span style='background-color:#EEEE00'>".$a."</span>", $txt);
$txt = str_ireplace($h, "<span style='background-color:#EEEE00'>".$h."</span>", $txt);
이 모두 잘 작동하지만, 결과 출력 :
[hello] How [are] You
대신 :
[Hello] How [Are] You
(대괄호 색상 배경이다)
고마워. 당신이 (뿐만 아니라 메타 문자를 사용할 수있는) 단어의 전체 배열을 강조하려는 경우,
$txt = preg_replace("#\\b($a|$h)\\b#i",
"<span style='background-color:#EEEE00'>$1</span>", $txt);
... 나 :
또한 iireplace를 사용하는 이유는 소문자로도 변경하고 싶지만 대문자로 유지하려면 자본을 계속 유지해야한다는 것입니다. – FoxyFish
내부적으로'str_ireplace'는'$ search'와'$ replace'를 소문자로 변환하여 일치하는 것을 찾습니다. 이것은 답이 아니라 문제가 발생한 이유를 설명합니다 – naththedeveloper