CakePHP에 스크립트에서 단어를 찾아서 바꾸는 기능이 있습니까?CakePHP 1.3 : 스크립트에서 단어 찾기 및 바꾸기 기능을 수행합니다.
"나쁜 단어"와 "단어 바꾸기"가 포함 된 데이터베이스가 있습니다.
ID | Bad Words | Replace Words
1 | ABC | ABC1
2 | EDF | EDF1
3 | GHI | GHI1
나는 사용자가 텍스트 영역에 스크립트를 입력 할 수있는 권한을 가지고 있습니다. 제출을 푸시하면 스크립트의 모든 나쁜 단어가 데이터베이스의 대체 단어로 바뀝니다.
어떻게 스크립트에서 잘못된 단어를 찾아서 데이터베이스 내용으로 바꿀 수 있습니까?
모든 의견과 제안에 감사드립니다.
EDIT :
嬢-----------手
看護婦-----------看護師
スチュワーデス-----------フライトアテンダント
百姓-----------農民
ブラインドタッチ-----------タッチタイピング
保母-----------保育士
ヤンキー-----------アメリカ人
word_check()은 : 2014년 11월 18일
여기서 데이터 표시가보기 같을 것이다 내 컨트롤러
class MAvoidanceWordsController extends AppController{
//The function to check bad words in script
function word_check()
{
//If the submit button (name is "check") is pushed.
if(isset($_POST['check']))
{
//Get all value in form
$script_content = $this->data;
//Query in database
$avoidance_list = $this->MAvoidanceWord->find('all');
//Get Avoidance word
$this->set("word_data",$word_data);
foreach ($word_data as $word_item):
echo $word_item['MAvoidanceWord']['avoidance_word'];
echo "-----------";
echo $word_item['MAvoidanceWord']['replace_word'];
echo "<br/>";
endforeach;
}
}
인 스크립트를 검사하는 기능.
echo $ word_item [ 'MAvoidanceWord'] [ 'avoidance_word'];은 나쁜 단어 내용 배열이됩니다
echo $ word_item [ 'MAvoidanceWord'] [ 'replace_word'];은 대체 단어 콘텐츠의 배열이됩니다
나는 나쁜 단어 데이터의 배열을 확인하고 이미 필터로 바꾸십시오. 양식에서 제출하고 대체하는 스크립트에서 단어 하나 하나를 확인하고 싶습니다.
사용하려고 시도했습니다. preg_replace ($ badWords, $ replaceWords, $ userText);하지만 UTF-8 코딩이 중단됩니다. "str_replace"은 동일합니다.
편집 : 2014년 11월 19일는 문제는 이제
을 통해서 문제를 해결할 나는 문제를 해결하는 방법을 찾아 냈다. 여기에 최종 코드가 있습니다. 희망이 더 많은 사람들 이이 상황에 도움이 될 것입니다. 단어를 교체function word_check()
{
//Read data from textarea on from
if(isset($_POST['check']))
{
$script_content = $this->data['MAvoidanceWord']['textarea'];
$word_data = $this->MAvoidanceWord->find('all',array(
'fields' => 'avoidance_word,replace_word',
'conditions' => array('invalid_flg' => '0')
));
foreach ($word_data as $word_item):
$bad[] = $word_item['MAvoidanceWord']['avoidance_word'];
$good[] = $word_item['MAvoidanceWord']['replace_word'];
endforeach;
$result = str_replace($bad, $good, $script_content);
$this->set('view_result',$result);
}
}
당신이 당신의 예상 출력을 줄 수 있습니까? – Sadikhasan
OK, Sth like : 텍스트 영역에 스크립트로 내용을 입력합니다. Sumbit 버튼을 누르고 나면 시스템은 데이터베이스의 "나쁜 단어"목록을 검사하고 스크립트에 바이 트 단어 (존재하는 경우)를 바꾸고 다시보기에 표시합니다. – TommyDo