Languages :: PHP :: rtrim() or explode()? |
|||
| By: roe1and |
Date: 06/11/2007 15:35:54 |
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 | Type : Comment |
|
| perhaps none of both ;-) substr($bob,0,-2); will do it faster |
|||
| By: roe1and | Date: 06/11/2007 19:58:01 | 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 | 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 | Type : Comment |
|
| awesome | |||
| By: VGR | Date: 07/11/2007 18:33:13 | Type : Comment |
|
| PHP ***is*** awesome ;-) | |||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








