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.



 Subscribe in a reader

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

Notices


Reply
 
LinkBack Thread Tools
  #1  
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
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
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] )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Apr 23rd, 2006, 20:14
Rob's Avatar
Rob Rob is online now
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,160
Blog Entries: 7
Thanks: 27
Thanked 19 Times in 16 Posts
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
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder

Last edited by Rob; Apr 23rd, 2006 at 20:18.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
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;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
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 22:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization 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