SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old September 23rd, 2004, 03:41 AM
eddynazrul eddynazrul is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: 192.168.1.4
Posts: 21 eddynazrul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Arrow How to split the value of this variable

I have one variable name $mobile.
The $mobile hold the value of mobile number which is 10 digit only.
Let say :

$mobile = '0192995682';

So how do I split this value '0192995682' and seperate that number and store it to two new variable.

$first = '019';
$last = '2995682';

The $first variable hold the first 3 digit of the $mobile value and $last hold the value digits left.

I want the $mobile value in split because i have to know the first 3 digit.Beacuse in my page i gonna
do some checking regard of this digit.

Anyone,help me please!

Reply With Quote
  #2  
Old September 23rd, 2004, 03:50 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
In php you have access to any string as an array of characters. So you could easily create first as follows -

$first = $mobile[0] . $mobile[1] . $mobile[2];

Failing that (and for any more advanced functionality you might need) look up the str* functions at www.php.net which do all kinds of string splicing.

-KM-

Reply With Quote
  #3  
Old September 23rd, 2004, 04:35 AM
eddynazrul eddynazrul is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: 192.168.1.4
Posts: 21 eddynazrul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Now I know. Thank u kode monkey. But i figure it out using substr() function.

$first = substr($mobile,0,3);

Then i got the digits that i want.
But many thanks for your information.

Reply With Quote
  #4  
Old September 23rd, 2004, 06:35 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
Yeah thats a much nicer way to do it, my way is definitely a bit of a hack.

-KM-

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > How to split the value of this variable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway