Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-06-27, 09:09 PM
Junior Member
 
Join Date: Jun 2004
Posts: 6
achilleas
Default

Hi. I am trying to cut the portions of a date XX/XX/XXXX where Xs are numbers

This is a portion of my code:

$date = "9/2/1983";
$pos1 = strpos($date, "/");
$pos2 = strpos($date, "/", $pos1+1);
echo $pos1."
";
echo $pos2."
";
$day = substr($date, 0, $pos1);
$month = substr($date, $pos1+1, $pos2-1);
$year = substr($date, $pos2+1, strlen($date));


it seems that i cannot get the month correctly. I can't understand why.
Note that the date will be entered from a form and will have a british type (Day/Month/Year).

help!!! )

Thank you
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2004-06-27, 10:09 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

$date = explode("/", "9/2/1983");
$day = $date[0];
$month = $date[1];
$year = $date[2];

http://www.php.net/explode
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2004-06-28, 04:23 AM
Guest
Guest
 
Posts: n/a
Default

hi

Xnuiem (congrats...) definitely showed you the best and quickest solution for parsing strings.
anyway, in case you'd like to find out more about the mess with 0-based/1-based functions,
send me a note, i've built a code-snippet which i can send you. the most important thing
in the behaviour of some functions is to understand the difference they handle position and length.
positions are 0-based, which means you have to deal with a calculation-base of zero (real offset 1 is 0).
lengths are 1-based (real).

Code:
$month  = substr($testdate, $start1, $len1);
                       |      |__________ 1-based
                       |_________________ 0-based
Beat
(Beat is a firstname here in Switzerland, so don't feel bothered...)
Reply With Quote
  #4 (permalink)  
Old 2004-06-28, 04:25 AM
Junior Member
 
Join Date: Jun 2004
Location: Zurich - Switzerland
Posts: 4
beath
Default

sorry i wasn't logged in before. my nick is beath if you want the code-snippet
__________________
PHP-Beginner. In return I can offer hints and tips on HTML, Javascript, CSS, HW, SW, Network etc.
Reply With Quote
  #5 (permalink)  
Old 2004-07-16, 04:44 AM
satish annavarapu
Guest
 
Posts: n/a
Default

Quote:
Originally posted by beath@Jun 28 2004, 08:25 AM
i would like to view how the date field validation is going
:huh:
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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



All times are GMT -5. The time now is 11:45 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.