Search code examples
phpstringerase

how to replace text using variable in PHP?


im doing to using STOP WORD for erase some conjuntion words : like this, the, in .

im still using read string then replace from file then erase those conjuntion words and here is the code

$fh = fopen("search/E_a_02.txt", "r");

$file = file_get_contents("search/E_a_02.txt");
$stop="BI";
echo str_replace($stop, "", $file);

i want that variable $stop is like array , that include stop words, then erase the sentence from the file, what should i do?

pleaseee help.

thank you master :)


Solution

  • Try:

    $stop = array("this","the","in");
    echo str_replace($stop, "", $file);
    

    It should replace all occurrence of $stop in $file