I have a local xampp version with php (7.4.4), that is fetching text from a mysql database and replacing specific texts in it. I am running the script in PHPStorm as "PHP Script" manually for debugging. However, it matches, but it does not replace. I have a small example to check that:
$description = join(" ", $words);
if(preg_match("/\(\s*see\s*\)/", $description)) {
echo $result['id']." Matches\n";
}
preg_replace(["/\(from\s*\)/", "/\(\s*see\s*\)/"], "", $description);
if(preg_match("/,/", $etymologies)) {
echo "Word ". $result['kirundi0'] . " with id ". $result['id']. " has multiple etymologies and now description: " . $description. "\n";
}
So, when I feed it with the sentence: "1. one, single, 2. some (with pl. prefix ), 3. same, (see )" the last part should be cut off, since it references something I removed. The log you can see in the console is:
3164 Matches
Word -mwe with id 3164 has multiple etymologies and now description: 1. one, single, 2. some (with pl. prefix ), 3. same, (see )
So it matches with preg_match, but there is never a replace happening. I was trying the pattern with the W3Schools preg_replace example and even there it works perfectly fine. Also regex101.com says there´s no issue with it. The text is not too long, that should be perfectly fine for my php.ini
Actually I am even confused about that behaviour, since I used preg_replace at the same server in another project already and it worked perfectly fine.
Have you tried?
$yourVar = preg_replace(["/\(from\s*\)/", "/\(\s*see\s*\)/"], "", $description);
According to documentation preg_replace does not work by reference.