The problem I’m encountering with this is if I have single characters in the array $wordstodelete it then deletes them from words in the $oneBigDescription.
$oneBigDescription = str_replace ( $wordstodelete, '', $oneBigDescription);
So it makes it look like this:
array (size=51)
'blck' => int 5
'centrl' => int 6
'clssc' => int 6
'club' => int 10
'crs' => int 54
'deler' => int 7
'delers' => int 5
'engl' => int 6
'felne' => int 8
'gude' => int 5
'hot' => int 5
'jgur' => int 172
'jgurs' => int 5
'lke' => int 6
Is there a way to only delete the single character from $oneBigDescription if it is on its own?
$oneBigDescription = preg_replace("/\b$wordstodelete\b/", '', $oneBigDescription);/bshould look for word boundaries to ensure it’s an isolated word when one character is used.EDIT: Didn’t quite read that right – this is more assuming you’re looping over $wordstodelete as an array of words.
So, something like this:
EDIT2: Wasn’t quite happy with this, so refined slightly:
This account for taking out the following space, which in HTML isn’t usually an issue when rendered (since consecutive spaces aren’t generally rendered), but still a good idea to take it out. This also creates an array of regex expressions up front, which seems a bit nicer.