visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: rtrim() or explode()?


By: roe1and Great Britain  Date: 06/11/2007 15:35:54  English French  Points: 20 Status: Answered
Quality : Excellent
$bob = "00074-5";

if i want to get rid of the -5 bit at the end, can i rtrim() it or do i HAVE to explode() it?
By: VGR Date: 06/11/2007 19:36:48 English  Type : Comment
perhaps none of both ;-)

substr($bob,0,-2); will do it faster
By: roe1and Date: 06/11/2007 19:58:01 English  Type : Comment
the trouble is $bob could be 00074-5 or 00074-56 and everything after the - has to go. stupid $bob!
By: VGR Date: 06/11/2007 21:09:07 French  Type : Answer
no problem. strrpos() is your friend ;-)

$a=strrpos($bob,'-'); if ($a!==FALSE) $bob=substr($bob,0,$a); // et voila



if you're not cautious, don't care about readability or maintanability and have disabled NOTICES and WARNINGS, you may write $bob=substr($bob,0,strrpos($bob,'-'));
By: roe1and Date: 07/11/2007 14:13:37 English  Type : Comment
awesome
By: VGR Date: 07/11/2007 18:33:13 English  Type : Comment
PHP ***is*** awesome ;-)

Do register to be able to answer

EContact
browser fav
page generated in 104.618790 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page