Splitting a variable

This is a discussion on "Splitting a variable" within the PHP Forum section. This forum, and the thread "Splitting a variable are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 21st, 2006, 10:48
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Splitting a variable

I have a 8 digit variable im taking from a database which I want to split in the 2-2-4 digits i.e. 12345678 -> 12 34 5678 does anyone know if its possible.
Reply With Quote

  #2 (permalink)  
Old Mar 21st, 2006, 15:01
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Splitting a variable

Sorted it now, for anyone thats interested its
$variable = AABBCCCC;
$CCCC = $variable % 10000; //CCCC
$BB = ($variable-$CCCC)/10000 % 100; //BB
$AA = ($variable-$BB)/1000000 % 100; //AA
Reply With Quote
  #3 (permalink)  
Old Mar 21st, 2006, 15:39
Junior Member
Join Date: Mar 2006
Location: Bradford, West Yorkshire, UK
Age: 25
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jdickinson Send a message via AIM to jdickinson Send a message via MSN to jdickinson Send a message via Yahoo to jdickinson Send a message via Skype™ to jdickinson
Lightbulb Re: Splitting a variable

Another way to do this is using the substr function (http://uk.php.net/substr):

string substr ( string string, int start [, int length] )
Reply With Quote
  #4 (permalink)  
Old Apr 23rd, 2006, 20:14
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: Splitting a variable

djme..... I should put your reply in the webforumz hall of fame and frame it!!!

The most hillarious cack handed code bodge I've seen in ages..

ROFL... classic
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work

Last edited by Rob; Apr 23rd, 2006 at 20:18.
Reply With Quote
  #5 (permalink)  
Old Apr 23rd, 2006, 20:39
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Splitting a variable

LOL I didn't realise there was a function to do it - I learnt it from a C++ book a few years ago and then thought it might work for this!
Reply With Quote
  #6 (permalink)  
Old May 14th, 2006, 05:52
New Member
Join Date: Mar 2006
Age: 23
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Splitting a variable

PHP: Select all

function _split($nstr)
{
 
$str1=substr($nstr,0,2);
 
$str2=substr($nstr,2,2);
 
$str3=substr($nstr,4,4);
 
$dstr=$str1." ".$str2." ".$str3;
 return 
$dstr;

Reply With Quote
Reply

Tags
splitting, variable

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
variable classes CloudedVision PHP Forum 4 Feb 14th, 2008 03:07
I'm used to just splitting tables, how can I do this in css? mad samuel Web Page Design 2 Aug 10th, 2007 17:36
is this variable right? geyids PHP Forum 4 Aug 6th, 2007 21:45
Site Splitting Ross H Webforumz Cafe 2 Mar 18th, 2007 16:16
Need help on image splitting sovereign6 Graphics and 3D 3 Jul 14th, 2005 17:44


All times are GMT. The time now is 20:50.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43