DeeDee Posted April 7, 2011 Share Posted April 7, 2011 Hello I have two requests that I need advice and help on. 1. I am trying to code a textfield only input that only accept characters instead of integers and special characters. I was thinking of using ereg shown here. if (!ereg($letters, $Myname)) { echo Letters only required'; } Is there a better way of comparing characters using utf-8 or ASCII using one if statement rather than using separate if statements for integers and special characters. 2. I am trying to code a method that would update the date into a via button. So far I have coded this, however it is not working <html> <head> </head> <body> <?php $submit = $_POST['submit']; if($submit){ for ($i = 40; $i < 100; $i++) { $i = time() + ($i * 24 * 60 * 60); } } echo 'Next Week: ' . date('Y-m-d', $i) . "\n"; ?> <form> <input type="submit" name="submit" value="update"/> </form> </body> </html> Some advice is grateful Thank you Link to comment Share on other sites More sharing options...
Jonathon Posted April 7, 2011 Share Posted April 7, 2011 Hi DeeDee, I would use preg_match instead or eregi as its deprecated and use a patter similar to [Az-aZ]. I will take a look at the second part when I'm home too. 1 Link to comment Share on other sites More sharing options...
Stuart Posted April 7, 2011 Share Posted April 7, 2011 Hi DeeDee, With regards the second part - what exactly are you trying to achieve? The code as it stands: <html> <head> </head> <body> <?php $submit = $_POST['submit']; if($submit){ for ($i = 40; $i < 100; $i++) { $i = time() + ($i * 24 * 60 * 60); } } echo 'Next Week: ' . date('Y-m-d', $i) . "\n"; ?> <form> <input type="submit" name="submit" value="update"/> </form> </body> </html> You have no method set in your form tag meaning it will default to GET rather than POST The echo statement is outside of the loop meaning it will only echo the next week line once 100 * 24 * 60 * 60 will be 100 days away not next week You can't redefine $i inside the loop else when it executes a second time it wont have the correct value 1 Link to comment Share on other sites More sharing options...
DeeDee Posted April 7, 2011 Author Share Posted April 7, 2011 Hi DeeDee, With regards the second part - what exactly are you trying to achieve? The code as it stands: <html> <head> </head> <body> <?php $submit = $_POST['submit']; if($submit){ for ($i = 40; $i < 100; $i++) { $i = time() + ($i * 24 * 60 * 60); } } echo 'Next Week: ' . date('Y-m-d', $i) . "\n"; ?> <form> <input type="submit" name="submit" value="update"/> </form> </body> </html> You have no method set in your form tag meaning it will default to GET rather than POST The echo statement is outside of the loop meaning it will only echo the next week line once 100 * 24 * 60 * 60 will be 100 days away not next week You can't redefine $i inside the loop else when it executes a second time it wont have the correct value Hi Stuart To answer your question (and perhaps for other users as well) on what I am trying to acheive is to change the date via submit button that, when clicked is meant to go past the current date. I hope this answers your question (oh btw the next week line is just a placement, in fact I just wanted to see the output of the date). Thanks to all who so far replied. Link to comment Share on other sites More sharing options...
Stuart Posted April 8, 2011 Share Posted April 8, 2011 Still unsure as to what dates you want to output (how many? how far in the future?) but the code below is the basic principal: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ for ($i = 1; $i < 11; $i++){ $timestamp = time() + ($i * 24 * 60 * 60); echo '<p>' . date('Y-m-d', $timestamp) . '</p>'; } } ?> <form method="post"> <input type="submit" name="submit" value="Update" /> </form> 1 Link to comment Share on other sites More sharing options...
DeeDee Posted April 8, 2011 Author Share Posted April 8, 2011 Still unsure as to what dates you want to output (how many? how far in the future?) but the code below is the basic principal: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ for ($i = 1; $i < 11; $i++){ $timestamp = time() + ($i * 24 * 60 * 60); echo '<p>' . date('Y-m-d', $timestamp) . '</p>'; } } ?> <form method="post"> <input type="submit" name="submit" value="Update" /> </form> As much and as far as possible, in other words there is no limit. Oh and thank you for your help. Link to comment Share on other sites More sharing options...
Stuart Posted April 8, 2011 Share Posted April 8, 2011 No worries - that code there is outputting the next 10 days. By increasing the number it could produce any date up to 2038 - which is the limit for UNIX timestamps (that's still true as far as I know). If you wanted to output dates in the future you might also want to check out strtotime which allows for something like: echo date('Y-m-d', strtotime('+ one week')); Link to comment Share on other sites More sharing options...
Larry Posted April 8, 2011 Share Posted April 8, 2011 As for the first question, you can use preg_match(), but you can also use ctype_alpha(), which may be easier: http://www.php.net/manual/en/function.ctype-alpha.php 1 Link to comment Share on other sites More sharing options...
DeeDee Posted April 8, 2011 Author Share Posted April 8, 2011 Great Ill check that out Larry, thanks so much!! Link to comment Share on other sites More sharing options...
Recommended Posts