此功能是我创建的创建半独特内容的系统的一部分,但是此功能需要运行 350* 200 字并且需要很长时间(300 秒以上)我想知道是否有任何明显的减速代码。
<?php
set_time_limit(0);
function spinthis($article)
{
//words to be replaced
$words = file_get_contents('words.txt', FILE_USE_INCLUDE_PATH);
$checker = "2";
//Explode each word of the article into $word
foreach (explode(" ", $article) as $word) {
$checker = "4";
$checker2 = "0";
if($word != '') {
if (strpos($words, $word) == true) {
//Explode each line of words.txt into $spinLine
foreach (explode("\n", $words) as $spinLine) {
//Explode each word from the chosen line
foreach (explode("|", trim($spinLine, '{}')) as $spinword) {
$stage2count = count(explode("|", $spinLine));
//if word matches grab the rest of the lines
if ($spinword == $word) {
$replaceWords = explode("|", trim($spinLine, '{}'));
shuffle($replaceWords);
//Add replacement word
$newword = str_replace('}','',$replaceWords[0]);
$newword = str_replace('}','',$newword);
$newword = lcfirst($newword);
$earticle = $earticle.' '.$newword;
$checker = "1";
break 2;
}else{
$checker2++;
if ($checker2 == $stage2count) {
$checker = "0";
break 1;
}
}
}
}
}else{
$checker = "0";
$checker2++;
}
}
//CHECK IF IT IS A WORD
if ($checker == '0'){
//Word not found
$earticle = $earticle . ' ' . $word;
}elseif($checker == '1'){
//Word found
//Do Nothing
}elseif($checker == '2'){
//First time
$earticle = $word;
}
}
return $earticle;
}
?>
words.txt 文件包含许多以下内容:
{address|Tackle|Handle|Target}
{add|Include|Incorporate|Increase|Put}
{adequate|Sufficient|Satisfactory|Ample}
{adjustment|Realignment|Adjusting|Modification|Change}
{adjust|Alter|Change|Modify|Regulate}
{administer|Give|Provide|Dispense|Render}
{administration|Management|Supervision|Government}
{administrator|Manager|Supervisor|Officer|Owner}
{admire|Appreciate|Enjoy|Respect|Adore}
{admission|Entrance|Entry|Programs|Everyone}
{admit|Acknowledge|Confess|Disclose|Declare}
{adolescent|Teenage}
{adoption|Ownership|Usage|Use}
{adopt|Follow|Embrace|Undertake}
{adult|Grownup|Grown-up|Person}
{advanced|Advanced level|High level|Higher level|Sophisticated}
{advance|Progress}
{advantage|Benefit|Edge|Gain}
{adventure|Journey|Experience|Venture|Voyage}
{advertising|Marketing|Promotion}
{advice|Guidance|Assistance}
{adviser|Agent|Advisor|Mechanic|Coordinator}
{advise|Recommend|Suggest|Guide|Encourage}
{advocate|Suggest|Supporter}
{ad|Advert|Advertisement|Advertising|Offer}
{aesthetic|Visual|Cosmetic|Artistic|Functional}
{affair|Event|Matter|Occasion}
{affect|Impact|Influence}
{afford|Manage}
{afraid|Scared|Frightened|Reluctant|Fearful}
{afternoon|Mid-day|Morning|Day|Evening}
{agency|Company|Organization|Firm|Bureau}
{agenda|Plan|Goal|Schedule|Intention}
{agent|Broker|Realtor|Adviser|Representative}
{age|Era}
{aggression|Hostility|Violence}
{aggressive|Intense|Hostile|Ambitious|Extreme}
{ago|Previously|Before}
{agreement|Contract|Arrangement|Settlement|Deal}
{agree|Concur|Consent|Acknowledge|Recognize}
{agricultural|Farming}
{agriculture|Farming}
{ahead|Forward|Onward}
{ah|Oh}
{aide|Assist|Help|Guide|Benefit}
{aid|Help|Support|Assist|Assistance}
{aim|Goal|Purpose|Intention}
{aircraft|Plane|Airplane}
{airline|Flight}
{airplane|Plane|Aircraft|Airline|Jet}
{air|Atmosphere|Oxygen}
{aisle|Section|Fence}
{alarm|Alert}
{album|Recording|Record|Lp|Cd}
{alcohol|Booze|Liquor}
{alien|Unfamiliar|Noncitizen|Nonresident|Strange}
{alike|Likewise|Equally}
{alive|Living|Well}
{allegation|Claims|Claim|Accusation}
{allegedly|Presumably|Apparently|Purportedly|Theoretically}
{alleged|So-called|Supposed|Claimed|Assumed}
{alley|Street}
{alliance|Connections|Coalition}
{allow|Permit|Enable|Let}