smile_mk Posted October 26, 2009 Share Posted October 26, 2009 Hi, Im hoping this is a simple one for you guys because its not for me. What im trying to do is automaticlly split a number. So say someone enters into a form 1234567890 I would like to somehow show that number as 1234 567890 as well as 1234567890 but without having to manually edit it. I hope you understand what I am trying to explain. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/179039-solved-split-a-number/ Share on other sites More sharing options...
Daniel0 Posted October 26, 2009 Share Posted October 26, 2009 Is it always of length 10 (or at least of length 5)? In that case you can do this: $num = substr($n, 0, 4) . ' ' . substr($n, 4); See substr in the manual. Quote Link to comment https://forums.phpfreaks.com/topic/179039-solved-split-a-number/#findComment-944626 Share on other sites More sharing options...
smile_mk Posted October 26, 2009 Author Share Posted October 26, 2009 Thank you so much for the fast reply, sadly that was straight over my head as im very very new to all this. I will however read the link you have provided and attempt to learn this. In the mean time I will explain exactly what im trying to acheive. Im using wordpress so using this code to fetch my title which I want to split. <?p hp the_title(); ?> (I added the space in php in case it does not show) The number is mostly always more than 5. So the code need to fetch the title then split it. Quote Link to comment https://forums.phpfreaks.com/topic/179039-solved-split-a-number/#findComment-944628 Share on other sites More sharing options...
smile_mk Posted October 26, 2009 Author Share Posted October 26, 2009 I have found this code. It is editable by me, im ok at edidting things but the one thing I cannot get to work it the start with. I need it to pick up the post title, then convert it for me. I have not edidted this yet but am confident I can do it. All I need help with is how to start with the post title. When I add <?php the_title(); ?> which is the wordpress way of doing it, it does not work. <? $start_with = "MY POST TITLE HERE"; $string = preg_replace("![^0-9]!", "", $start_with); $part1 = substr($string,0,3); $part2 = substr($string,3,3); $part3 = substr($string,6,4); $array = array( "(", $part1, ") ", $part2, "-", $part3); $phone_num = implode("",$array); echo $phone_num; ?> Quote Link to comment https://forums.phpfreaks.com/topic/179039-solved-split-a-number/#findComment-944636 Share on other sites More sharing options...
smile_mk Posted October 26, 2009 Author Share Posted October 26, 2009 Placing <?ph p the_title(); ?> in the starte_with area does not work. Can anyone suggest a solution to use the post title as the starts_with entry. Quote Link to comment https://forums.phpfreaks.com/topic/179039-solved-split-a-number/#findComment-944643 Share on other sites More sharing options...
smile_mk Posted October 26, 2009 Author Share Posted October 26, 2009 Replaced <?php the_title(); ?> With get_the_title($post->post_parent); And it now works. SOLVED Quote Link to comment https://forums.phpfreaks.com/topic/179039-solved-split-a-number/#findComment-944645 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.