Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    142
    Thanks
    9
    Thanked 1 Time in 1 Post

    strtotime question

    $_POST['date'] equals a date and time in this format: 9/6/08 6:00 pm

    If I just do this it converts properly to a timestamp:

    Code:
    $timestamped = strtotime("9/6/08 6:00 pm");
    But if it is passed along in a form it doesn't work for me anymore. Like this:

    Code:
    $game_time = $_POST['date'];
    $timestamped = strtotime($game_time);
    We just changed servers so I can't help but wonder if that may be the problem because I'm pretty sure it worked fine before but I haven't used this script in many months.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,009
    Thanks
    2
    Thanked 312 Times in 304 Posts
    Have you echoed $_POST['date'] to see what it actually contains and please define: "it doesn't work for me anymore". Telling or showing what you see in front of you would help someone determine what exactly is going wrong.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Jan 2007
    Posts
    142
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by CFMaBiSmAd View Post
    Have you echoed $_POST['date'] to see what it actually contains and please define: "it doesn't work for me anymore". Telling or showing what you see in front of you would help someone determine what exactly is going wrong.
    Yes, I can echo out the $game_time variable. But when I echo out the $timestamped variable it doesn't contain anything at all.

    I even added this to see the results that follow:

    Code:
    $game_time = $_POST['date'];
    $timestamped = strtotime($game_time);
    $timestamped2 = strtotime("9/6/08 6:00 pm");
    
    echo 'game_time is ' . $game_time . '<br />';
    echo 'timestamped is ' . $timestamped . '<br />';
    echo 'timestamped2 is ' . $timestamped2 . '';
    game_time is 9/6/08 6:00 pm
    timestamped is
    timestamped2 is 1220742000

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,009
    Thanks
    2
    Thanked 312 Times in 304 Posts
    I would guess that the POST variable contains some non-printing characters. Add the following two lines immediately after your first opening <?php tag -

    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    Use var_dump() to see more about what the variable contains -

    PHP Code:
    var_dump($_POST['date']); 
    And can you post the form so that someone could try to duplicate the results.

    Edit: Another possibility is that $timestamped corresponds to a post/get/cookie/session variable due to register_globals. Change the variable name to something else as a test.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    Jan 2007
    Posts
    142
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by CFMaBiSmAd View Post
    I would guess that the POST variable contains some non-printing characters. Add the following two lines immediately after your first opening <?php tag -

    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    Use var_dump() to see more about what the variable contains -

    PHP Code:
    var_dump($_POST['date']); 
    And can you post the form so that someone could try to duplicate the results.

    Edit: Another possibility is that $timestamped corresponds to a post/get/cookie/session variable due to register_globals. Change the variable name to something else as a test.
    No errors reported.

    The var_dump printed this:

    string(15) "9/6/08 6:00 pm"

    I changed the name to $timestamped3 and same result.

    The file is database driven so I stripped it down to the basics to test and it gives the same problem. I have also run this on a separate server and gotten the same result.

    Code:
    <html>
    <head>
    	<title>Edit the Football Schedule</title>
    
    </head>
    <body>
    
    <?php
    ini_set ("display_errors", "1");
    error_reporting(E_ALL);  
    
    if(isset($_POST['submit']))
    {
    	$game_time = $_POST['date'];
    	$timestamped3 = strtotime($game_time);
    	$timestamped2 = strtotime("9/6/08 6:00 pm");
    	  
    	echo 'game_time is ' . $game_time . '<br />';
    	echo 'timestamped is ' . $timestamped3 . '<br />';
    	echo 'timestamped2 is ' . $timestamped2 . '';
    	var_dump($_POST['date']); 
    }
    
    $new_date = "9/6/08";
    $new_time = "6:00 pm";
    
    echo '
    
    <center><br /><font size="9" color="#cc0000"><b>Edit Football Schedule</b></font><br />
    
    <table border="1" width="75%" cellpadding="3">
    
    			<tr>
    				<td><center><b>Date/Time</b></center></td>
    				<td><center><b>Edit</b></center></td>
    			</tr>
    
    		<form action="' .$_SERVER['PHP_SELF']. '" method="post">
    			<tr>
    				<td align="center"><input type="text" size="15" name="date" value="' . $new_date . '&nbsp;' . $new_time . '" /></td>
    				<td align="center"><input type="submit" name="submit" value="Edit" /></td>
    				
    			</tr>
    		</form>
    </table>
    </center>';
    
    ?>
    
    </body>
    </html>

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,009
    Thanks
    2
    Thanked 312 Times in 304 Posts
    The problem is the non-breaking space between the date and time in the form value. I tried using html_entity_decode(), but that did not change anything. The only thing I can think that is probably at fault is the default page encoding that the web server is using. You could try putting in a specific character set encoding in the head of the document.

    I recommend just using a literal space character instead of &nbsp; in this case.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    unrelenting (08-10-2008)

  • #7
    Regular Coder
    Join Date
    Jan 2007
    Posts
    142
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by CFMaBiSmAd View Post
    The problem is the non-breaking space between the date and time in the form value. I tried using html_entity_decode(), but that did not change anything. The only thing I can think that is probably at fault is the default page encoding that the web server is using. You could try putting in a specific character set encoding in the head of the document.

    I recommend just using a literal space character instead of &nbsp; in this case.
    Genius!

    I removed that non-breaking space symbol and it prints correctly now. Awesome. Thanks.

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,009
    Thanks
    2
    Thanked 312 Times in 304 Posts
    I played around with this some more and it appears this is an IE browser problem (possibly combined with the page character encoding.) It works with &nbsp; in FF.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #9
    Regular Coder
    Join Date
    Jan 2007
    Posts
    142
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by CFMaBiSmAd View Post
    I played around with this some more and it appears this is an IE browser problem (possibly combined with the page character encoding.) It works with &nbsp; in FF.
    It must be a character encoding issue then. I had some character encoding issues with my data displaying on the new server but I thought it was just the way it dumped. I used a different script to dump and upload and the character problems went away. I dunno.

    I was using FF the whole time and it never did work for me so that may enhance your suggestion that it's a character encoding issue.

    I'm just glad to be done with it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •