mike1313 Posted March 22, 2007 Share Posted March 22, 2007 I've read the documentation on php.net, but still dont full understand. $string = '123456'; $return = substr("$string", 1); echo "$return"; I know that $return will echo 23456. But How can I for instance, using substr be able to echo 345, 456, 56? Please any help is appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/43841-solved-substr-help/ Share on other sites More sharing options...
Orio Posted March 22, 2007 Share Posted March 22, 2007 This is what you need to keep in mind: string substr ( string $string, int $start [, int $length] ) <?php //345- substr($string, 2, 3); //456- substr($string, 3, 3); //56- substr($string, 4, 2); ?> Orio. Link to comment https://forums.phpfreaks.com/topic/43841-solved-substr-help/#findComment-212822 Share on other sites More sharing options...
mike1313 Posted March 22, 2007 Author Share Posted March 22, 2007 Well say in a form, they input "123456 How are you?" using substr how would I get rid of just 1 2 3 4 at each step? I guess what I'm saying is it possible with an unknown str length? Link to comment https://forums.phpfreaks.com/topic/43841-solved-substr-help/#findComment-212824 Share on other sites More sharing options...
Orio Posted March 22, 2007 Share Posted March 22, 2007 You want to remove the first 4 characters? <?php substr($string, 0, 4); ?> Maybe if you explain exactly what you want to do it would be easier to solve your problem. Orio. Link to comment https://forums.phpfreaks.com/topic/43841-solved-substr-help/#findComment-212827 Share on other sites More sharing options...
mike1313 Posted March 22, 2007 Author Share Posted March 22, 2007 This is jumbled but this is the code. if($xy9 > "0" && $xy9 < "10") { $do_pm3 = substr("$do_pm2", 1); } elseif($xy9 > "10" && $xy9 < "100") { $do_pm3 = substr($do_pm2, 0, 2); } elseif($xy9 > "100" && $xy9 < "1000") { $do_pm3 = substr("$do_pm2", 0, 3); } elseif($xy9 > "1000" && $xy9 < "10000") { $do_pm3 = substr("$do_pm2", 0, 4); } The only string returning anything is the first. Link to comment https://forums.phpfreaks.com/topic/43841-solved-substr-help/#findComment-212834 Share on other sites More sharing options...
Orio Posted March 22, 2007 Share Posted March 22, 2007 What are you trying to do? Orio. Link to comment https://forums.phpfreaks.com/topic/43841-solved-substr-help/#findComment-212836 Share on other sites More sharing options...
mike1313 Posted March 22, 2007 Author Share Posted March 22, 2007 $xy9 returns a number if that number is a certain number I need it to filter out the beginning of a string. I tried using strlen instead of $xy9=100 I just need it to search for a number if its that number remove it from the string. or if strlen=2, 3, 4 I need to remove the 2nd, 3rd, 4th, characters of the string. say strlen=2 I want substr to remove the 2 characters, 3, 4 and so on. Link to comment https://forums.phpfreaks.com/topic/43841-solved-substr-help/#findComment-212837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.