Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-02-2007, 09:30 AM   PM User | #1
Morf
New Coder

 
Join Date: Apr 2006
Posts: 47
Thanks: 2
Thanked 0 Times in 0 Posts
Morf is an unknown quantity at this point
Splitting a string into 2 variables

Hello.

I'm having trouble splitting a string into 2 variables in the following situation:

an outside script from an affiliated site is going to post to my script using GET method, they will give me a numeric string and unfortunately, I cannot modify their script.

The string will be posted using the get method and named 'sid'

so for example, it may be ?sid= 1009102

Now here's what I want to do:

I need to "grab" the first 4 digits, and pass them into one variable.

There may be any number of digits after that, I'll need to pass those digits into a second variable.

For the above example, I'd need it to pass into the following:

$variable1 = 1009
$variable2 = 102

However, should there be more digits, such as in this example, I'll need to tack them onto the end of $variable2 :

?sid=101020000

$variable1 = 1010
$variable2 = 20000

In other words, the first four digits will always be passed into $variable1 and anything else will be passed into $variable2

I've never done anything of this nature before so any help is appreciated.

Thanks!
Morf is offline   Reply With Quote
Old 01-02-2007, 09:49 AM   PM User | #2
koyama
Senior Coder

 
koyama's Avatar
 
Join Date: Dec 2006
Location: Copenhagen, Denmark
Posts: 1,246
Thanks: 1
Thanked 5 Times in 5 Posts
koyama will become famous soon enough
How about this?
Code:
$var = '1009102';
$variable1 = substr($var, 0, 4);
$variable2 = substr($var, 4);
koyama is offline   Reply With Quote
Old 01-02-2007, 10:38 PM   PM User | #3
Nicklas
New Coder

 
Join Date: Jun 2006
Location: Sweden
Posts: 49
Thanks: 0
Thanked 3 Times in 3 Posts
Nicklas is on a distinguished road
or like this

PHP Code:
$var '101020000';
list(
$var1$var2) = explode('|'substr_replace($var'|'40)); 
Nicklas is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:06 PM.


Advertisement
Log in to turn off these ads.