PHP - Echo "time=" . Time(); But Format To: Tue Mar 1 23:50:00 Gmt-0300 2011 Example
Hey Guys!
I have the following doubt. When echoing from Server like this: Code: [Select] echo "time=" . time(); I get the time in the following raw format: 1299272294 I would really like to echo it with this format: Tue Mar 1 23:50:00 GMT-0300 2011 Is there a way I could do that? Really looking forward for some help on this one, Thanks a lot in advance! Cheers! Similar TutorialsI want to have a couple of different formats from mktime(), which the value could be: 1292183335. I would like to have some of the formats like: Tuesday at 12:00am, Wednesday, January 12, 2011 at 12:00am Also taking different timezones in consideration. I'm not sure what to use for that. Hello I am trying to only display results within the time period last sunday too next sunday. my code: Code: [Select] <?php $today = date('Y-m-d H:i:s'); $time = strtotime($today); $last_sunday = strtotime('last sunday', $time); $next_sunday = strtotime('next sunday', $time); $format = 'Y-m-d H:i:s'; $last_sunday = date($format, $last_sunday); $next_sunday = date($format, $next_sunday); ?> <?php $sql_totalsurfs = ("SELECT vtp_members.id, vtp_members.name, vtp_members.teamleader, vtp_tracking.Timber, vtp_tracking.Stone, vtp_tracking.Marble, teams.team_name, count(vtp_tracking.id) surfs FROM vtp_members, vtp_tracking, teams WHERE vtp_members.team_id=".$_GET['t']." AND vtp_tracking.credit_members_id=vtp_members.id AND vtp_tracking.action_date>'$last_sunday' AND vtp_tracking.action_date<'$next_sunday' GROUP BY vtp_members.id ORDER BY surfs DESC LIMIT 0, 10"); $rstotalsurfs = mysql_query($sql_totalsurfs); $numrows = mysql_num_rows($rstotalsurfs); ....... Is there and error somwhere in the code? Greetings to all! I am very new to this so I may not be on the right track. I am providing some code I have because I think this is the best way to explain what I am trying to do. I have a database and php pages that generate a pedigree when one selects any particular dog from the search page. If anyway has a tip on how to simplify this, I would sure appreciate it!! First, I request an array for the dog selected: Code: [Select] $sql = "SELECT RegName, SireID, DamID FROM pedigrees WHERE ID="; $thisDogQ = $sql . $values["ID"]; $thisDogR = db_query($thisDogQ,$conn); $thisDogRow_value = mysql_fetch_assoc($thisDogR); $thisDogRow_value = array ( 'RegName' => $thisDogRow_value['RegName'], 'SireID' => $thisDogRow_value['SireID'], 'DamID' => $thisDogRow_value['DamID']); </code> //Next I request the same information for his sire <code> if (is_numeric($thisDogRow_value['SireID'])) { $query_SireQ = $sql . $thisDogRow_value['SireID']; $SireR = mysql_query($query_SireQ, $conn) or die(mysql_error()); $SireRow_value = mysql_fetch_assoc ($SireR); $SireRow_value = array ( 'RegName' => $SireRow_value['RegName'], 'SireID' => $SireRow_value['SireID'], 'DamID' => $SireRow_value['DamID']); </code> //and then his dam <code> if (is_numeric($thisDogRow_value['DamID'])) { $query_DamQ = $sql . $thisDogRow_value['DamID']; $DamR = mysql_query($query_DamQ, $conn) or die(mysql_error()); $DamRow_value = mysql_fetch_assoc ($DamR); $DamRow_value = array ( 'RegName' => $DamRow_value['RegName'], 'SireID' => $DamRow_value['SireID'], 'DamID' => $DamRow_value['DamID']); </code> Now, here's the rub: Now I need the sire and the dam for those 2 [described above] so this time through, I will need the same information for FOUR dogs. The next time will be for EIGHT, then SIXTEEN - and so on until there are a total of 256 dogs. <code> //Get PatGrandSire 2 if (is_numeric($SireRow_value['SireID'])) { $PatGrandSireQ = $sql . $SireRow_value['SireID']; $PatGrandSireR = mysql_query ($PatGrandSireQ, $conn) or die(mysql_error()); $PatGrandSireRow_value = mysql_fetch_assoc ($PatGrandSireR); $PatGrandSireRow_value = array ( 'RegName' => $PatGrandSireRow_value['RegName'], 'SireID' => $PatGrandSireRow_value['SireID'], 'DamID' => $PatGrandSireRow_value['DamID']); //GetPatGrandDam 17 if (is_numeric($SireRow_value['DamID'])) { $PatGrandDamQ = $sql . $SireRow_value['DamID']; $PatGrandDamR = mysql_query ($PatGrandDamQ, $conn) or die(mysql_error()); $PatGrandDamRow_value = mysql_fetch_assoc ($PatGrandDamR); $PatGrandDamRow_value = array ( 'RegName' => $PatGrandDamRow_value['RegName'], 'SireID' => $PatGrandDamRow_value['SireID'], 'DamID' => $PatGrandDamRow_value['DamID']); //Get Pat1GGrandSire-3 if (is_numeric($PatGrandSireRow_value['SireID'])) { $Pat1GGrandSireQ = $sql . $PatGrandSireRow_value['SireID']; $Pat1GGrandSireR = mysql_query ($Pat1GGrandSireQ, $conn) or die(mysql_error()); $Pat1GGrandSireRow_value = mysql_fetch_assoc ($Pat1GGrandSireR); $Pat1GGrandSireRow_value = array ( 'RegName' => $Pat1GGrandSireRow_value['RegName'], 'SireID' => $Pat1GGrandSireRow_value['SireID'], 'DamID' => $Pat1GGrandSireRow_value['DamID']); if (is_numeric($PatGrandSireRow_value['DamID'])) { $Pat1GGrandDamQ = $sql . $PatGrandSireRow_value['DamID']; $Pat1GGrandDamR = mysql_query ($Pat1GGrandDamQ, $conn) or die(mysql_error()); $Pat1GGrandDamRow_value = mysql_fetch_assoc ($Pat1GGrandDamR); $Pat1GGrandDamRow_value = array ( 'RegName' => $Pat1GGrandDamRow_value['RegName'], 'SireID' => $Pat1GGrandDamRow_value['SireID'], 'DamID' => $Pat1GGrandDamRow_value['DamID'], 'Title' => $Pat1GGrandDamRow_value['Title'], 'Title2' => $Pat1GGrandDamRow_value['Title2'], 'Title3' => $Pat1GGrandDamRow_value['Title3'], 'Title4' =>$Pat1GGrandDamRow_value['Title4'], 'Title5' => $Pat1GGrandDamRow_value['Title5'], 'Title6' =>$Pat1GGrandDamRow_value['Title6'], 'Title7' => $Pat1GGrandDamRow_value['Title7'], 'Title8' =>$Pat1GGrandDamRow_value['Title8'], 'Title9' => $Pat1GGrandDamRow_value['Title9'], 'Addl_Titles' => $Pat1GGrandDamRow_value['Addl_Titles']); //Get Pat2GGrandSire-18 if (is_numeric($PatGrandDamRow_value['SireID'])) { $Pat2GGrandSireQ = $sql . $PatGrandDamRow_value['SireID']; $Pat2GGrandSireR = mysql_query ($Pat2GGrandSireQ, $conn) or die(mysql_error()); $Pat2GGrandSireRow_value = mysql_fetch_assoc ($Pat2GGrandSireR); $Pat2GGrandSireRow_value = array ( 'RegName' => $Pat2GGrandSireRow_value['RegName'], 'SireID' => $Pat2GGrandSireRow_value['SireID'], 'DamID' => $Pat2GGrandSireRow_value['DamID'], 'Title' => $Pat2GGrandSireRow_value['Title'], 'Title2' => $Pat2GGrandSireRow_value['Title2'], 'Title3' => $Pat2GGrandSireRow_value['Title3'], 'Title4' => $Pat2GGrandSireRow_value['Title4'], 'Title5' => $Pat2GGrandSireRow_value['Title5'], 'Title6' => $Pat2GGrandSireRow_value['Title6'], 'Title7' => $Pat2GGrandSireRow_value['Title7'], 'Title8' => $Pat2GGrandSireRow_value['Title8'], 'Title9' => $Pat2GGrandSireRow_value['Title9'], 'Addl_Titles' => $Pat2GGrandSireRow_value['Addl_Titles']); //Get Pat2GGrandDaminfo-25 if (is_numeric($PatGrandDamRow_value['DamID'])) { $Pat2GGrandDamQ = $sql . $PatGrandDamRow_value['DamID']; $Pat2GGrandDamR = mysql_query ($Pat2GGrandDamQ, $conn) or die(mysql_error()); $Pat2GGrandDamRow_value = mysql_fetch_assoc ($Pat2GGrandDamR); $Pat2GGrandDamRow_value = array ( 'RegName' => $Pat2GGrandDamRow_value['RegName'], 'SireID' => $Pat2GGrandDamRow_value['SireID'], 'DamID' => $Pat2GGrandDamRow_value['DamID']); I apologizing for bothering the expert here again, but I've run into another issue. I am using the following code because I can't change the default timezone on my shared hosting plan: $time = date("h:i A", strtotime("+19 hours")); there are few issues with this. if I just use: date("h:i: A") the time prints as 7 hours earlier than my timezone, and currently it shows 1:09 AM and it appears in the database as "01:09:00". if I use the code above, the time prints out as "08:09 PM", but it is inserted into the database as "08:09:00". Shouldn't it read "20:09:00" instead? and why isn't the time being inserted into the database with the "PM" suffix on it like it appears in the printout? the "time" field in my database is set to type TIME. thanks. Edited October 14, 2019 by ajetrumpetThis topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342600.0
Question:
Background:
Example: The Pacific ("Los Angeles") time right now is 7:58pm, but my code says it's 6:58pm. So now I have to go in and correct the "PT8H" portion. I'm wondering if there is some code I can use whereby I can simply "set it and forget it." Thank you! Edited May 2, 2020 by StevenOliverhello, I was wondering what is the point of writing for a dropdown: <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> or for a checkbox/ radio button: <?php if ($_POST['cb/radioID'] == "value") { echo "checked"; } ?> I guess it's for after submit, if there is any error, the values filled will still be echoed in the inputfield, or am i wrong? But then if that is true, i have a php search box where i use AJAX object to to send all the input they filled in after submit. But after pushing submit the inputted values remain. I guess when using AJAX to send the information i don't need <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> in my html forms? Little confused Can maybe somebody bring clearness Can someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> How can i make echo "<b>Site:</b> ".$req_user_info['site']."<br>"; linkable The site raw fron the db contains an site url. Regards Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob Code: [Select] function time_ago($timestamp) { //$months = array("Jan" => 31, "Feb" => 28, "Mar" => 31, "Apr" => 30, "May" => 31, "Jun" => 30, "Jul" => 31, "Aug" => 31, "Sept" => 30, "Oct" => 31, "Nov" => 30, "Dec" => 31); $curr_time = time(); $time_ago = $curr_time - $timestamp; if($time_ago < 60) // seconds { $ext = $time_ago . " seconds ago.."; } else { if($time_ago >= 60) // minutes { $time = floor($time_ago / 60); $seconds_remainder = $time_ago % 60; $ext = $time . " minutes " . $seconds_remainder . " seconds ago.."; if($time >= 60) // hours { $hours = floor($time / 60); $minutes = $time % 60; $ext = $hours . " hours " . $minutes . " minutes ago.."; if($hours >= 24) // days { $days = floor($hours / 24); $day_hours = $hours % 24; $ext = $days . " days " . $day_hours . " hours ago .."; } } } } return $ext; } It seems to work fine (was going to tackle Months but haven't done it yet), but anyway is there a better way to do this? I'm guessing there is as I wrote this up rather fast and I'm not that great with date math. Any suggestions are appreciated (besides maybe using ternaries which I'm working on atm). Code: [Select] function time_ago($timestamp) { //$months = array("Jan" => 31, "Feb" => 28, "Mar" => 31, "Apr" => 30, "May" => 31, "Jun" => 30, "Jul" => 31, "Aug" => 31, "Sept" => 30, "Oct" => 31, "Nov" => 30, "Dec" => 31); $curr_time = time(); $time_ago = $curr_time - $timestamp; if($time_ago < 60) // seconds { $ext = $time_ago . " seconds ago.."; } else { if($time_ago >= 60) // minutes { $time = floor($time_ago / 60); $seconds_remainder = $time_ago % 60; $ext = $time . " minutes " . $seconds_remainder . " seconds ago.."; if($time >= 60) // hours { $hours = floor($time / 60); $minutes = $time % 60; $ext = $hours . " hours " . $minutes . " minutes ago.."; if($hours >= 24) // days { $days = floor($hours / 24); $day_hours = $hours % 24; $ext = $days . " days " . $day_hours . " hours ago .."; } } } } return $ext; } Is there a cleaner approach to this? Hi guys I am a newbie with PHP and I have been trying to solve this problem for 3 days.. Ive set up a booking form on my website to be sent directly to my email once the client clicked on the send button.. The problem I am having while checking these pages on wamp is that the booking form is ok but when I click on the send button the following message error appears "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\fluffy_paws\booking_form2.php on line 27" When I check online I have this message "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." Are my codes wrong??? My webhosting is Blacknight.com , Im on Windows Vista, my internet is a dongle with O2 ireland Thanks for your help! I am creating a series of PHP scripts that allow for someone to append extra information to an Accident Claim Report. One of these scripts lists the files in a directory called the RCM directory. For the purpose of this, there is only one file in the list named "denman2.txt" and a hyperlink is attached to it so that the updated Accident Claim Report can be displayed. However, I would like it so that a style sheet could be applied to the "denman2.txt" text file, and I was wondering how it would be possible for the "denman2.txt" file to be opened in a format such as an HTML format so that a style sheet can be applied to it. Here is my Append Code: Code: [Select] <html> <head><title>Amend File</title></head> <?php if($_POST['append'] !=null) { $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file=fopen($filename, "a"); $msg="Updated Information: " .$_POST['append']. "<br>"; fputs ($file, $msg); fclose($file); } ?> <body> <h1>Do you want to append to a document?</h1> Enter Updated Information: <form action="amendfile2.php" method="post"> <input type="text" size="40" name="append"><br><br> <input type="submit" value="Add updated information to report"> </form> <form action="viewfile3.php" method="post"> <input type="submit" value="View Web Blog"> </form> </body></html> My View File Code: Code: [Select] <html><head> <title>RCM File List</title></head> <body> <h1>Files in RCM Directory</h1> <?php $dir="C:/xampp/htdocs/rcm/*txt"; foreach(glob($dir) as $file) { $list = "<li><a href='readfile2.php'>Filename: $file</a></li>"; } ?> <ul> <?php echo $list; ?> </ul> </body> </html> And my Read File Code: Code: [Select] <html><head><title>Reading Accident Reports</title></head> <body> <?php function myErrorHandler($errno, $errstr) { echo "<b>Error: </b> [$errno] $errstr"; echo "<br>"; echo "End scripting"; die(); } set_error_handler("myErrorHandler"); $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file = fopen($filename, "r"); while (!feof($file)) { $line=fgets($file,1024); echo "$line<br>"; } fclose($file); ?> </body> </html> Any help is appreciated Hello I have a from that updates a few things in the db, and uses "<?php echo $PHP_SELF;?>". The form does update everything fine, however that page does not reflect it. If I refresh the page manually I can see the new values. Is this a common thing, and can anything be done to fix this? Hi guys I'm struggling a bit, I need to replace a word that occurs multiple times in text with an array("up","down","forward","backwards") of words. $find = "left"; $replace = array("up","down","forward","backwards"); $text = "left left left left"; echo str_replace($find,$replace,$text); The Output is: array array array array Did try this with a foreach statement as well, but no luck. Is there a better way of doing this? Thanks Hi all - I am a novice when it comes to PHP, but I have managed to use it successfully many times. I have an issue where I can not get a variable to echo when I am calling it from within a file that is using SSI. Here is a basic example that should explain it better. In the /index.php file: Code: [Select] <?php $photo1="photo1.jpg"; $photo2="photo2.jpg"; ?> <?php include('http://www.DOMAIN.com/includes/header.php'); ?> In the /header.php file: <img src="http://www.DOMAIN.com/photos/<?php echo $photo1; ?>"> When I try to echo $photo1 from within the /header.php file it simply does nothing, even though the variable is declared before the call for the include file. If I try to do the echo with the IMG tag from within the /index.php file, it works no problem -but that wont work without a MAJOR site redesign with how things are configured. Question is, why does this not work, and how can I fix it? Huge thanks from this Newb! Hello, all... I seem to remember, like if I have a problem with a mysql_query() statement, and want find out why it keeps giving me an error, I'm often told to echo out the statement for debugging purposes. Can somebody remind me again how that's done... thanks! Good evening -- My script takes a while to execute as it processes records from the db. I'd like to have it print out to the screen the record id # as it processess each record, just to let me know where it is. Currently, the program waits till the end and then prints out the record numbers, which is no help. How can I enable PHP to print out each record number as it goes along? Thanks!
Hello All, function convertTimeFormat($time12Hour) { // Initialized required variable to an empty string. $time24Hour = ""; // Used explode() function to break the string into an array and stored its value in $Split variable. $Split = explode(":",$time12Hour); // print_r(explode (":", $time12Hour)); => Array ( [0] => 09 [1] => 50 [2] => 08AM ) // Retrieved only "hour" from the array and stored in $Hour variable. $Hour = $Split[0]; $Split[2] = substr($Split[2],0,2); // Used stripos() function to find the position of the first occurrence of a string inside another string. if($Hour == '12' && strpos($time12Hour,"AM")!== FALSE) { // Code here } elseif(strpos($time12Hour,"PM")!== FALSE && $Hour != "12") { // code here } return $time24Hour; } $time12Hour = "09:50:08AM"; $result = convertTimeFormat($time12Hour); print_r($result); /* Input : "09:50:08AM"; Output : "21:50:08PM"; */
|