$myVar = 'essa pizza é muito gostosa';
$myWords=array(
array('sabor','gosto','delicia'),
array('saborosa','gostosa','deliciosa'),
);
foreach($myWords as $words){
// randomize the subarray
shuffle($words);
// pipe-together the words and return just one match
if(preg_match('/\b\K'.implode('|',$words).'\b/',$myVar,$out)){
// generate "replace_pair" from matched word and a random remaining subarray word
// replace and preserve the new sentence
$myVar=strtr($myVar,[$out[0]=>current(array_diff($words,$out))]);
}
}
echo $myVar;
Should be replaced by:
$myVar = 'essa pizza é muito deliciosa';
or
$myVar = 'essa pizza é muito saborosa';
But you are trading for smaller word keys, just because this smaller key also contains all the letters of this larger key!
The Output is happening is wrong:
$myVar = 'essa pizza é muito saborsa';
"saborsa" (this word does not exist in Portugues and too in my arrays)!
Is cutting the word "gostosa", to put the word "sabor" Then, instead of entering the word "tasty," is forming the word that does not exist: "saborsa". A part of the word "gostosa" = "sa" + word "sabor" = "saborsa" (this word does not exist) has to be tasty.
How to read the full key / word before doing the replacement? Thanks
Aucun commentaire:
Enregistrer un commentaire