나는 php에서 매우 새로운데, php에서 두 번째 스크립트입니다. 단어 단위로 음역을 변환하는 음역 도구입니다. txt 파일에서 데이터를 읽고 각 단어를 새 것으로 바꿉니다. 그것은 작은 텍스트에 대해 정말로 효과적이지만, 텍스트가 크다면 실패합니다. 제발 도와주세요.PHP의 음역 응용 프로그램
이없는 str_replace 5 번해야 할 이유를 우선 들어<?php
$Urdu = array();
$Roman = array();
$str2replace = $_POST["S1"];
$Chr1 = array("'", '"', "!", " (", ") ", "@", "#", "$", "%", "^", "&", "*", ",", ".", "/", "?", "<", ">", ";", "[", "]", "{", "}", "،", "۔" , "؟", "+", "-", "=", "_");
$Chr2 = array(" ' ", ' " ', " ! ", " (", ") ", " @ ", " # ", " $ ", " % ", "^", " & ", " * ", " , ", " . ", "/", " ? ", " < ", " > ", " ; ", " [ ", " ] ", " { ", " } ", " ، ", " ۔ " , " ؟ ", " + ", " - ", " = ", " _ ");
$str2replace = " " . $str2replace . " ";
$str2replace = str_replace(array("\n", "\r"), '', $str2replace);
$str2replace = str_replace($Chr1 , $Chr2, $str2replace);
$file = fopen("Dict.txt", "r");
while (!feof($file)) {
$String = fgets($file);
$String = str_replace(array("\n", "\r"), '', $String);
$pos = strrpos($String, "/");
if ($pos === false) {
// Not Found
} else {
$Urdu[] = " " . substr($String, 0,$pos) . " " ;
$Roman[] = " " . substr($String, $pos+1) . " " ;
}
}
fclose($file);
$str2replace = str_replace($Urdu, $Roman, $str2replace);
$str2replace = str_replace($Chr2 , $Chr1, $str2replace);
$str2replace = substr($str2replace, 1);
echo $str2replace;
?>
전환하는 데 너무 많은 시간이 걸리며 페이지가 손상 될 수 있습니다. 개선을위한 아이디어를 찾고 있습니다. – user934820