여기서 막혔어요 도와주세요~

문자열 치환함수인데요....
 
 
아래의 소스대로 하면,
 
mildly가 입력되면 이상il복부 가 출력됩니다. 순차적으로 일치하는 단어만을 출력하게 되는데요
 
이를 정확하게 일치하는 단어만 출력되게 하는 방법이 있을까요? mildly를 입력하면 "경미하게" 출력되게끔요
 
 
 
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

function bad_Word($str)
 {     
$str=str_replace("m","이상",$str);
$str=str_replace("mil","경",$str);
$str=str_replace("dly","복부",$str);
$str=str_replace("ased","외전",$str);
$str=str_replace("localized","후방 관절",$str);
$str=str_replace("increased","증가된",$str);
$str=str_replace("mildly","경미하게",$str);

   
 return $str;
 }   

?>
 
 
 
 
 
 
 
아래는 내용출력부분 입니다
 
 
<?
                   //<!-- 단어변환-->
     if ($member[mb_level] >= "12"){echo "<span class='ct lh'>".$view[content]."</span>";}
      else{
      
      
      $content = bad_Word($view[content]);
      echo "<span id=\"writeContents\">".$content."</span>";
       }
        ?>
|

댓글 8개

$str=str_replace("mildly","경미하게",$str);
$str=str_replace("increased","증가된",$str);
$str=str_replace("localized","후방 관절",$str);
$str=str_replace("ased","외전",$str);
$str=str_replace("dly","복부",$str);
$str=str_replace("mil","경",$str);
$str=str_replace("m","이상",$str);


이렇게 반대로 하면 되지 않을까요 ^^;
치환하는 단어가 2만개입니다 ㅜㅡ
정확히 일치하는 문자열만 출력하는 방법이 없을까요?
글자길이로 소팅후 치환순서를 정한후 str_replace 에 array 인자로 넣어주심댈듯
function Word($str) {
$a_res = array("m"=>"이상", "mil"=>"경", "dly"=>"복부", "ased"=>"외전", "localized"=>"후방 관절", "increased"=>"증가된", "mildly"=>"경미하게");

return $a_res[$str];
}
치환 문자열과, 치환대상 문자열을 배열로 만들어서 저장하면 됩니다.
stop word(아마 공백이 되겠죠.) 단위로 나눠서 변환을 하면 됩니다.
연속되어 있는 문자는 위에서 얘기한것쩌럼 긴쪽부터 변환해야 합니다.
이렇게 해도 안돼요 ㅠㅠ

function bad_Word($str)
{
$a_res = array('m' =>'이상','mil'=>'경','dly'=>'복부','ased'=>'외전','localized'=>'후방 관절','increased'=>'증가된','mildly'=>'경미하게');
$str = str_replace($a_res, $str);
return $str;
}
제가 잘못이해했는지 모르겠습니다만, 정규표현식으로 하면 쉽게되지 않을까요??
답변 감사합니다^^
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
14년 전 조회 1,066
14년 전 조회 1,474
14년 전 조회 2,738
14년 전 조회 2,174
14년 전 조회 2,037
14년 전 조회 3,472
14년 전 조회 2,565
14년 전 조회 1,509
14년 전 조회 1,564
14년 전 조회 1,545
14년 전 조회 1,666
14년 전 조회 1,100
14년 전 조회 1,430
14년 전 조회 1,554
14년 전 조회 3,150
14년 전 조회 1,451
14년 전 조회 1,184
14년 전 조회 1,169
14년 전 조회 3,513
14년 전 조회 1,287
14년 전 조회 2,006
14년 전 조회 2,072
14년 전 조회 1,232
14년 전 조회 1,926
14년 전 조회 1,320
14년 전 조회 1,472
14년 전 조회 2,384
14년 전 조회 2,131
14년 전 조회 2,735
14년 전 조회 1,449
14년 전 조회 1,319
14년 전 조회 2,686
14년 전 조회 1,344
14년 전 조회 1,450
14년 전 조회 2,597
14년 전 조회 1,536
14년 전 조회 1,527
14년 전 조회 1,243
14년 전 조회 1,501
14년 전 조회 2,508
14년 전 조회 1,061
14년 전 조회 3,069
14년 전 조회 1,380
14년 전 조회 1,102
14년 전 조회 1,069
14년 전 조회 1,357
14년 전 조회 1,272
14년 전 조회 1,175
14년 전 조회 1,666
14년 전 조회 1,092
14년 전 조회 1,737
14년 전 조회 2,146
14년 전 조회 1,090
14년 전 조회 1,201
14년 전 조회 1,057
14년 전 조회 1,226
14년 전 조회 1,643
14년 전 조회 1,345
14년 전 조회 1,484
14년 전 조회 1,275
14년 전 조회 1,466
14년 전 조회 1,033
14년 전 조회 1,872
14년 전 조회 1,211
14년 전 조회 1,984
14년 전 조회 8,752
14년 전 조회 1,318
14년 전 조회 2,153
14년 전 조회 1,934
14년 전 조회 2,197
14년 전 조회 2,546
14년 전 조회 1,120
14년 전 조회 1,261
14년 전 조회 7,061
14년 전 조회 1,229
14년 전 조회 1,134
14년 전 조회 2,347
14년 전 조회 1,228
14년 전 조회 1,199
14년 전 조회 2,683
14년 전 조회 1,280
14년 전 조회 4,227
14년 전 조회 4,361
14년 전 조회 1,687
14년 전 조회 1,258
14년 전 조회 1,901
14년 전 조회 1,190
14년 전 조회 1,481
14년 전 조회 1,073
14년 전 조회 7,969
14년 전 조회 1,613
14년 전 조회 1,011
14년 전 조회 1,177
14년 전 조회 1,866
14년 전 조회 1,323
14년 전 조회 1,164
14년 전 조회 1,251
14년 전 조회 1,197
14년 전 조회 1,055
14년 전 조회 1,185