0

この関数は、私が作成した、ややユニークなコンテンツを作成するシステムの一部ですが、この関数は 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}
4

0 に答える 0