desithugg Posted October 7, 2006 Share Posted October 7, 2006 [code]<?php$show1 = "3232sad4.32342";function reverse_strrchr($haystack, $needle){ $pos = strrpos($haystack, $needle); if($pos === false) { return $haystack; } return substr($haystack, 0, $pos + 1);}$show = reverse_strrchr($show1, '.');echo $show;?>[/code]the code aove would echo 3232sad4. (everything before the .)but if i want to echo everything after the . what should i do? Quote Link to comment https://forums.phpfreaks.com/topic/23317-function/ Share on other sites More sharing options...
redbullmarky Posted October 8, 2006 Share Posted October 8, 2006 [code]<?php$show1 = "3232sad4.32342";list($before, $after) = explode('.', $show1);?>[/code]or[code]<?php$show1 = "3232sad4.32342";$parts = explode('.', $show1);$before = $parts[0];$after = $parts[1];?>[/code]or[code]<?php$show1 = "3232sad4.32342";$dotposition = strpos($show1, '.');$after = substr($show1, $dotposition + 1); ?>[/code]there are plenty more ways but these should get you goinghope it helpsCheersMark Quote Link to comment https://forums.phpfreaks.com/topic/23317-function/#findComment-105719 Share on other sites More sharing options...
printf Posted October 8, 2006 Share Posted October 8, 2006 Just a another method....[code]<?php$show1 = "3232sad4.32342";function reverse_strrchr ( $str, $find, $type = 0, $include = false ){ if ( ( $pos = strrpos ( $str, $find ) ) !== false ) { return ( $type == 1 ? $include ? substr ( $str, $pos ) : substr ( $str, $pos + 1 ) : substr ( $str, 0, ( $include ? $pos + 1 : $pos ) ) ); } return ( $str );}/*** reverse_strrchr ( param_1, param_2, $param_3, param_4 )** param_1 = haystack* param_2 = needle* param_3 = 0 -> return left side of needle, 1 -> return right side of needle* param_4 = BOOL return with needle -> true (include needle), false (don't include needle)**/// substring start of string (don't include 'needle')echo reverse_strrchr ( $show1, '.' );echo '<br />';// substring start of string (include 'needle')echo reverse_strrchr ( $show1, '.', 0, true );echo '<br />';// substring end of string (dont include 'needle')echo reverse_strrchr ( $show1, '.', 1 );echo '<br />';// substring end of string (include 'needle')echo reverse_strrchr ( $show1, '.', 1, true );echo '<br />';?>[code]me![/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/23317-function/#findComment-105722 Share on other sites More sharing options...
JasonLewis Posted October 8, 2006 Share Posted October 8, 2006 why write huge lines of code when u can use the explode and list method, whcih only takes one line. so much more simplier. Quote Link to comment https://forums.phpfreaks.com/topic/23317-function/#findComment-105739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.