homepage Welcome to WebmasterWorld Guest from 107.20.91.81
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Seperate Digits with Forward Slashes
matthewamzn




msg:3735700
 1:59 am on Sep 1, 2008 (gmt 0)

I need to take a series of numbers and separate them with slashes. Is there a php command I can use in my statement?

643502

to

6/4/3/5/0/2/

 

MattAU




msg:3735707
 2:23 am on Sep 1, 2008 (gmt 0)

You can do it pretty easily with a custom function.

function slash($var)
{
$var_slash = '';
for($i = 0; $i < strlen($var);$i++)
$var_slash .= $var[$i].'/';
return $var_slash;
}

coopster




msg:3736631
 5:40 pm on Sep 2, 2008 (gmt 0)

separate them with slashes

In your example there you didn't really separate them, matthewamzn, you added a slash after each one. If you just wanted to separate, you could combine a couple of functions:

$number = 643502; 
$newNumber = implode('/', str_split($number));

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved