How can I remove, with PHP, the last word from a String?
For example the string \"Hi, I\'m Gian Marco\" would become \"Hi, I\'m Gian\".
The current solution is ok if you do not know the last word and the string length is short.
In case you do know it, for instance when looping a concat string for a query like this:
foreach ($this->id as $key => $id) {
$sql.=' id =' . $id . ' OR ';
}
A better solution:
$sql_chain = chop($sql_chain," OR ");
Be aware that preg_replace with a regex is VERY slow with long strings. Chop is 100 times faster in such case and perf gain can be substantial.