How to implement my algorithm text correction for the replacement of words in the text?

风格不统一 提交于 2019-12-04 12:11:23

What @ctwheels wanted to tell you is to use str_ireplace (documentation), if you want to correct word with case-insensitive.

<?php
     $test="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
     $word=explode(" ",$test); //This function is need for take all the words individually, the link of the function is above
     foreach($word as $key=>$value)
        if (array_key_exists($value,$YourArrayWithCorrectWord))
            $word[$key]=$YourArrayWithCorrectWord[$value]; //This, if i don't make mistakes, take the correct word and assigns to the wrong word.

     $TestCorrect=implode(" ",$word);
?>

If there is something that you don't understand, write me.

I hope I have helped you.

Documentation: Here the documentation of explode

Here the documentation of implode

Here the documentation of array_key_exsist

P.S. This method have the problem that you can't correct two or more words together.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!