Guest Posted January 30, 2003 Share Posted January 30, 2003 Does anyone now how to code this in PHP ----------> Remove the last character of a string, IF the last letter of the string is a "S" ???? People search my site in the keywrods for dogs and the descriptions in my item file read dog, so the search results come up with nothing. :? Link to comment Share on other sites More sharing options...
Aodhan Posted January 30, 2003 Share Posted January 30, 2003 Does anyone now how to code this in PHP ---------->Remove the last character of a string, IF the last letter of the string is a "S" ???? People search my site in the keywrods for dogs and the descriptions in my item file read dog, so the search results come up with nothing. :? What happens if they search for an item such as "Glass"? Wouldn't a strpos be a better way? $where = strpos($description, $search_term); if (!is_integer($where)) { // we didn't find it... } (Code hacked for readibility from the MAN pages. Aodhan Link to comment Share on other sites More sharing options...
blueline Posted February 1, 2003 Share Posted February 1, 2003 There is an array function available in PHP that allows you to delete the last character. Don't exactly remember what it is though. I will think of it and post it here tomorrow. -Chris Chris Sullivan Link to comment Share on other sites More sharing options...
Christian Lescuyer Posted February 1, 2003 Share Posted February 1, 2003 Remove the last character of a string, IF the last letter of the string is a "S"? <?php $string = 'beers'; print eregi_replace('s$', '', $string); ?> Christian Lescuyer Link to comment Share on other sites More sharing options...
Guest Posted March 1, 2003 Share Posted March 1, 2003 Thanks Christian, The code works great and it solved my problem. Sorry it took so long to test out. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.