Phear46 Posted May 12, 2013 Share Posted May 12, 2013 I want to remove the last ' AND' from my string im using to build a mySQL query. I thought using rtrim was the way to go but either im wrong or im not using it correctly: foreach ($dupArray as $k => $v) { $whereStr = $whereStr . "$k='$v' AND "; } rtrim($whereStr, "AND"); echo $whereStr; Anyone got any ideas? I swear ive seen this done else where but i cant find any examples Link to comment https://forums.phpfreaks.com/topic/277930-remove-substring-from-end-of-string/ Share on other sites More sharing options...
Barand Posted May 12, 2013 Share Posted May 12, 2013 try $str = "abcde AND "; echo substr($str, 0, -4); // --> 'abcde ' But if you store the WHERE conditions in an array then JOIN with " AND " you can avoid the problem Link to comment https://forums.phpfreaks.com/topic/277930-remove-substring-from-end-of-string/#findComment-1429725 Share on other sites More sharing options...
Jessica Posted May 12, 2013 Share Posted May 12, 2013 Your string ends with " AND ". Not "AND". Link to comment https://forums.phpfreaks.com/topic/277930-remove-substring-from-end-of-string/#findComment-1429731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.