PHP - Date Manipulation
Hello,
I have a code that adds 1 month to a specific date every month. Code: [Select] $newdate = strtotime ( '+1 month' , strtotime ( $b_date ) ) ; $new_date = date ( 'Y-m-d' , $newdate ); the thing is some month of the year do not contain the SAME amount of days. For example: If the date was 2011-01-31 + 1 month = 03-03-2011 Is there any way to add a month (+1 month) but make it consider the calendar. lets say that I had 2011-01-31 --> +1 month == 2011-28-02 (the last day of the next month if there is NO similar days in month Thanks Similar TutorialsHello I have this code: Code: [Select] $data = mysql_query("SELECT * FROM remind WHERE DATE_SUB(CURDATE(), INTERVAL 1 DAY) = event_date ") or die(mysql_error()); Basically what I need, I have a table (remind) with lots of dates of events (event_date). 1 day before the event and on the day of the event, I want to send an e-mail to my customers, automatically. This up mentioned code send e-mails to all the upcoming events, not ONLY to the ones TOMORROW or TODAY. I need something like this: If today is 01-01-2011 AND I have an event on 02-01-2011 I want that the SQL code will find and send the e-mail only for the event tomorrow and on 02-01-2011 send again the reminder of today's event. *I have events every day BUT I want to send a reminder ONLY 1 day before and on the day of the event. Any help ?? Please help! User enters Date (that is somewhere in future, few hours or maybe few years). I need to store in MYSQL Date minus 6 hours keeping in mind daylight savings time. I tried to convert date to unix timestamp and subtract 6*60*60. Works great, but does not take into consideration daylight savings time. Right, I have a 2 part question. At the moment, each user has an image stored for them which is linked to via a field in the database. Now I'm showing the image by a simple <img /> tag and just including the result of the filename from a database query, which works perfectly fine but I want to take this a step or two further. 1) Firstly, is it possible to get variables of width, height etc for images that are stored on the server as a file? Much like this information can be accessed when a user uploads an image, is it possible to do it if I'm showing the image once it's uploaded and stored? 2) If I can get dimensions for the image, is it possible to SCALE it properly down to a suitable size? For example, the maximum image can be 50 x 50, but images that are smaller would be scaled up PROPORTIONALLY or if they were bigger they would be scaled down PROPORTIONALLY. For example, if an image is 100 x 200, I don't want it scaled down to 50 x 50, I want it so that it remains to scale and is scaled down to 25 x 50. Hey guys having a problem with the following code which is supposed to change the case of the class name and include the resulting file. function __autoload($class_name) { $class_name = strtolower($class_name); $class_name .= ".php"; include $class_name; } However this throws the following error Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE on $class_name .= ".php"; I cannot figure out why I cannot append the string to the result of strtolower, can anyone tell me what's wrong? I am building an application that creates a label for a manufacturing company... it finds an appropriate font size for given text, and then draws it and displays the image as a bmp(it is required to be a bmp). That is all fine and dandy and working correctly. The problem is that the label must have a depth of 2 bits for it to work correctly on their machine...I am using the following code, but cannot get a bit depth lower than 24. iMagick and GD are both available on the server. Code: [Select] $text = $_GET['text']; if (isset($text)) { $image = new Imagick(); $image->setResolution(71.5, 71.5); $image->newImage(160, 40, new ImagickPixel('black')); $draw = new ImagickDraw(); $draw->setFillColor('white'); $draw->setStrokeColor(new ImagickPixel('black')); $draw->rectangle(0, 0, 159, 39); $font_size = 25; $font_name = 'arial.ttf'; do { $font_size--; $bbox=imagettfbbox($font_size, 0, $font_name, stripcslashes($text)); $right_text = $bbox[2]; $left_text = $bbox[0]; $width_text = $right_text - $left_text; $height_text = abs($bbox[7] - $bbox[1]); } while ($font_size>9 && ($height_text>40 || $width_text>160)); if ($height_text>40 || $width_text>160 || $font_size<10) { echo 'The text given will not fit on the label.<br />'; } else { $draw->setFont($font_name); $draw->setFontSize($font_size); $draw->setFillColor('black'); $draw->setTextAntialias(false); $draw->setGravity (Imagick::GRAVITY_CENTER); $draw->annotation(0, 0, stripcslashes($text)); $image->drawImage($draw); $image->blackthresholdImage( "#999999" ); $image->whitethresholdImage( "#999999" ); $image->setImageType(1); $image->setImageFormat('bmp'); $image->writeImage("flavor_labels/".$text.".bmp"); echo '<img src="flavor_labels/'.$text.'.bmp" /><br /><p>Right click this image and click Save As or Save Image As. <br />Enter in the desired label name and save it to the desired destination.</p>'; } } All, I have a part of code where I get a string or numbers like (234,2345,4536,45,75657...). Can you guys help figure out how I can get the last element of that particular string..i.e., i want to echo 75657 to screen and the likes. The last number is not a fixed size one. It can be a n digit number. I tried using array_pop and end. But it did not work. Suggestion or code snippets please. I am currently working on a website where users can go and upload images and select different types of filters for the images and then let the user see the result of the filter. This has all gone fine and the image filters are working, the only problem I am having is trying to add a function that allows the user to convert the image so that it looks like a Polaroid. I have seen sites that do similar things but cant work out how its done, wondering if someone could shed some light on the whole area? thanks Hello, I had this case: Text is stored in mysql table in the means of html, i.e. it contains <p> ,<br /> .... I want to display it on a php page, I had 2 questions: I want to display the first 400 characters, then the second 300 each on different <div> , so I need to save them each on different variable? and what about html tags? Thanks I am trying to find a workaround for people using bookmarks and executing them simultaneously forcing a script to run thousands of times in just a second. Is there a way I can implement a token or a short bit of javascript that would force the user to use the link vs bookmarked URL pages? Sorry if I am being vague here but its really causing me issues having people doing this on my site. Hi have an array() in which I would like to manipulate certain elements: Code: [Select] Array ( [TESCO] => Array ( [Veg] => Array ( [Potatoe] => 12 [Cabbage] => 24 [Cucumber] => 56 ) [Meat] => Array ( [Chicken] => 54 [Beef] => 89 ) ) [ASDA] => Array ( [Veg] => Array ( [Potatoe] => 12 [Cabbage] => 24 [Cucumber] => 56 ) [Meat] => Array ( [Chicken] => 23 [Beef] => 90 ) ) ) How would I go about adding the price of my meat section together e.g. Chicken + Beef from ASDA = 113 Also how to add/remove elements from Meat/Veg? Like adding Pork Cheers Hi. I have text files in the directory that contain rapidshare.com links. Now what I need to do is take them one by one and check links inside them one by one using rapidshare API. Everything works fine apart from one thing. It reads files and deletes the ones containing dead links but the problem is that it only deletes the file if ALL links are dead, but not when only one link is dead or some of them. Code: Code: [Select] <?php function rs_check($url){ if (!$url) return false; $files_pattern= '/\/files\/([^\/]*)\//'; $filename_pattern= '/\/files\/.*\/(.*)/'; preg_match($files_pattern, $url, $matches_id); preg_match($filename_pattern, $url, $matches_name); $res= file_get_contents("http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles_v1&files={$matches_id[1]}&filenames={$matches_name[1]}"); list($fId,$fName,$fSize,$fServerId,$fStatus,$fShortHost,$fmd5) =explode(',',$res); return ($fStatus==1 || $fStatus==2); } $directory = "download/"; $linksfiles = glob("" . $directory . "*.txt"); foreach($linksfiles as $linkfile) { $lf = file_get_contents($linkfile); $purefilename = str_replace($directory, "" , $linkfile); if($purefilename != "5100c00fdb545e12e8cb4f9c5f69ec21.txt"){ if(rs_check($lf) != 1){ unlink($directory . $purefilename); echo("<br />"); } } } ?> Hi all, I have heard stories that hackers/viruses or basically something that you don't want uploaded to a server through a website form have been able to type some sort of code in to a html form field to access information. I know how to control the length of fields, how to validate that an email address is in the correct format etc. - but when it comes to having a textfield for the user to add up to 2000 characters of their own words, how can I protect from malicious code being inserted? The textfield is located inside the user area but anyone can join, so anyone ultimately can enter code! Thanks for the help. Hi,
I currently have some html stored in a variable as below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> Hello world </body> </html>This requires a "<div class='container'>" to be inserted directly after the opening body tag. My original thinking was to use str_replace on the <body> to be <body><div class="container"> however note that occasionally my body will require an ID or Class. I therefore need a way to make it appear after the body tag, even if it has an ID or Class on it :-\ . I assume this may be reg-ex, but am not sure if there is a simple way around this? Would anyone be able to clarify and point me in the right direction. Much appreciated. MoFish Hi all, been a while since I've been on here.
I am in the process of designing a site similar to dating sites like plenty of fish, or ok cupid. The only spot I am running into trouble is with images.
If you are familiar with either of these sites, you will understand what I am looking for.
Basically, a user is able to upload one or more images via an uploader (Not sure if it's ajax or flash to be honest, but I would like to stick to PHP/Ajax).
While uploading, they have the ability to crop their images to specific sizes set by the site - for example, the image must be cropped to fit a 400 px X 400 px area, so they have the ability to decide which part of a larger image is saved rather than just have the system crop it and perhaps not show what was intended.
After they finish and click upload, the image is saved to the server, as well as a thumbnail, which, without a refresh, is then added to their page along with their previous images if there were any. From that point, they have the option to delete images they don't like, set the main image for their profile and edit/add captions to the images, again, all without refreshing the page.
Would anyone happen to know of a script I could start with and change to suit my needs, but that would pretty much allow this kind of image uploading/manipulation? I've done google searches for hours now and have looked at a ton of scripts but not a single one I have found seems to be able to do any of these things. Most just have multiple file uploads with cropping ability, but not by the users themselves, just a predetermined dimension.
Any help pointing me in the right direction would be greatly appreciated.
Jax
Hi pals, I got a complex Array from the Query. it's Structure is like Quote Array ( => Array ( [server_name] => anes.admod.net [id] => 1 [server_id] => 1 [description] => nice Anes Server [status] => 0 [max_down_count] => 9 [check_interval] => 15 [fail_recheck] => 6 [log_retain] => 1 [warning] => 12 [critical] => 15 [timeout] => 8 [audible] => Y [email] => Y [im] => Y [sms] => Y [rss] => N [rssid] => [vcare] => Y [created] => 2010-12-06 10:26:26 [last_update] => 2010-12-13 16:41:48 [name] => POP3 [port] => 110 [okay] => OK [warn] => WARNING [crit] => CRITICAL [down] => Connection refused [advanced] => N [typestatus] => 1 ) [1] => Array ( [server_name] => neseema.admod.net [id] => 2 [server_id] => 2 [description] => another server [status] => 1 [max_down_count] => 11 [check_interval] => 15 [fail_recheck] => 12 [log_retain] => 2 [warning] => 12 [critical] => 16 [timeout] => 6 [audible] => Y [email] => Y [im] => Y [sms] => N [rss] => N [rssid] => [vcare] => N [created] => 2010-12-07 10:27:42 [last_update] => 2010-12-13 16:41:48 [name] => Cpanel [port] => 2082 [okay] => OK [warn] => WARNING [crit] => CRITICAL [down] => Connection refused [advanced] => N [typestatus] => 1 ) [2] => Array ( [server_name] => anes.admod.net [id] => 3 [server_id] => 1 [description] => nice Anes Server another Service [status] => 1 [max_down_count] => 14 [check_interval] => 15 [fail_recheck] => 3 [log_retain] => 3 [warning] => 12 [critical] => 16 [timeout] => 18 [audible] => Y [email] => [im] => [sms] => [rss] => N [rssid] => [vcare] => N [created] => 2010-12-07 12:58:01 [last_update] => 2010-12-13 16:41:48 [name] => SMTP [port] => 25 [okay] => OK [warn] => WARNING [crit] => CRITICAL [down] => Connection refused [advanced] => N [typestatus] => 1 ) ) In this Result I have 2 Rows in result to show, I mean I need to merge the data of First (0th) and Third(2nd) element because it display the data of same item. So How it can done, I am working in that whole day but not get a solution fully.... I saw a near solution like : <?php $input = array( 0 => array ( 'id' => 160, 'payment_period' => 'Monthly', 'plan_payment_type_id' => 171, 'payment_type_id' => 4), 1 => Array ( 'id' => 160, 'payment_period' => 'Monthly', 'plan_payment_type_id' => 172, 'payment_type_id' => 5), 2 => Array ( 'id' => 161, 'payment_period' => 'Weekly', 'plan_payment_type_id' => 173, 'payment_type_id' => 9), ); echo "<pre>"; print_r($input); echo "</pre>"; echo "****************************************************************************"; $output = array(); $id_array = array(); $i = 0; foreach($input as $key=>$val) { if(array_key_exists($val['id'],$id_array)) { $pos = $id_array[$val['id']]; $output[$pos]['payment_types'][] = array('plan_payment_type_id'=> $val['plan_payment_type_id'],'payment_type_id' => $val['payment_type_id']); } else { $output[$i] = array('id' => $val['id'],'payment_period' => $val['payment_period'],'payment_types' => array(array('plan_payment_type_id'=> $val['plan_payment_type_id'],'payment_type_id' => $val['payment_type_id']))); $id_array[$val['id']] = $i; $i++; } } echo "<pre>"; print_r($output); echo "</pre>"; ?> But I cannot handle it nicely, please give any sample or helping code idea for same , waiting your immediate Reply Thankfully Anes P.A Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack I have my data array which i converted to json by splitting the keys using for each loop. Data:
$data = Array ( [table6-ios-camt] => [table6-ios-iamt] => [table6-ios-samt] => [table6-ios-type] => [table6-isd-camt] => 0 [table6-isd-iamt] => 0 [table6-isd-samt] => 0 [table6-isd-type] => [table6-ios-csamt] => [table6-isd-csamt] => 0 [table6-other-camt] => [table6-other-iamt] => [table6-other-samt] => [table6-other-type] => [table6-tran1-camt] => 0 [table6-tran1-iamt] => [table6-tran1-samt] => 0 [table6-tran1-type] => [table6-tran2-camt] => 0 [table6-tran2-iamt] => [table6-tran2-samt] => 0 [table6-tran2-type] => [table6-itc_3b-csamt] => 0 [table6-dump_iog-camt] => [table6-dump_iog-iamt] => [table6-dump_iog-samt] => [table6-dump_iog-type] => [table6-dump_oth-camt] => 4386.09 [table6-dump_oth-iamt] => [table6-dump_oth-samt] => 4386.09 [table6-dump_oth-type] => [table6-itc_clmd-camt] => [table6-itc_clmd-iamt] => [table6-itc_clmd-samt] => [table6-itc_clmd-type] => [table6-total_10-camt] => 4386.09 [table6-total_10-iamt] => 0 [table6-total_10-samt] => 4386.09 [table6-total_10-type] => [table6-total_11-type] => [table6-total_8-csamt] => 0 [table6-total_9-csamt] => 0 [table6-dump_iog-csamt] => [table6-dump_isrc-camt] => [table6-dump_isrc-iamt] => [table6-dump_isrc-samt] => [table6-dump_isrc-type] => [table6-dump_oth-csamt] => [table6-iog_goods-camt] => [table6-iog_goods-iamt] => [table6-iog_goods-samt] => [table6-iog_goods-type] => Capital Goods [table6-itc_clmd-csamt] => [table6-total_10-csamt] => 0 [table6-dump_isrc-csamt] => [table6-iog_goods-csamt] => [table6-iog_inputs-camt] => [table6-iog_inputs-iamt] => [table6-iog_inputs-samt] => [table6-iog_inputs-type] => Input Services [table6-iog_inputs-csamt] => [table6-iog_services-camt] => [table6-iog_services-iamt] => [table6-iog_services-samt] => [table6-iog_services-type] => Input Services [table6-supp_non_rchrg_goods-camt] => [table6-supp_non_rchrg_goods-iamt] => [table6-supp_non_rchrg_goods-samt] => [table6-supp_non_rchrg_goods-type] => Capital Goods [table6-supp_rchrg_reg_goods-camt] => [table6-supp_rchrg_reg_goods-iamt] => [table6-supp_rchrg_reg_goods-samt] => [table6-supp_rchrg_reg_goods-type] => Capital Goods [table6-supp_non_rchrg_goods-csamt] => [table6-supp_non_rchrg_inputs-camt] => 4386.09 [table6-supp_non_rchrg_inputs-iamt] => [table6-supp_non_rchrg_inputs-samt] => 4386.09 [table6-supp_non_rchrg_inputs-type] => Inputs [table6-supp_rchrg_reg_goods-csamt] => [table6-supp_rchrg_reg_inputs-camt] => [table6-supp_rchrg_reg_inputs-iamt] => [table6-supp_rchrg_reg_inputs-samt] => [table6-supp_rchrg_reg_inputs-type] => Input Services [table6-supp_non_rchrg_inputs-csamt] => [table6-supp_rchrg_reg_inputs-csamt] => [table6-supp_rchrg_unreg_goods-camt] => [table6-supp_rchrg_unreg_goods-iamt] => [table6-supp_rchrg_unreg_goods-samt] => [table6-supp_rchrg_unreg_goods-type] => Capital Goods [table6-supp_non_rchrg_services-camt] => [table6-supp_non_rchrg_services-iamt] => [table6-supp_non_rchrg_services-samt] => [table6-supp_non_rchrg_services-type] => Input Services [table6-supp_rchrg_reg_services-camt] => [table6-supp_rchrg_reg_services-iamt] => [table6-supp_rchrg_reg_services-samt] => [table6-supp_rchrg_reg_services-type] => Input Services [table6-supp_rchrg_unreg_goods-csamt] => [table6-supp_rchrg_unreg_inputs-camt] => [table6-supp_rchrg_unreg_inputs-iamt] => [table6-supp_rchrg_unreg_inputs-samt] => [table6-supp_rchrg_unreg_inputs-type] => Input Services [table6-supp_non_rchrg_services-csamt] => [table6-supp_rchrg_reg_services-csamt] => [table6-supp_rchrg_unreg_inputs-csamt] => [table6-supp_rchrg_unreg_services-camt] => [table6-supp_rchrg_unreg_services-iamt] => [table6-supp_rchrg_unreg_services-samt] => [table6-supp_rchrg_unreg_services-type] => Input Services [table6-supp_rchrg_unreg_services-csamt] => ); json: { "table6":{ "ios":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "isd":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "other":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "tran1":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "tran2":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "itc":{ "camt":0, "iamt":550, "samt":230, "csamt":680 }, "iog":[ { "itc_typ":"cg", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"ip", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"is", "camt":0, "samt":0, "iamt":0, "csamt":0 } ], "supp_non_rchrg":[ { "itc_typ":"cg", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"ip", "camt":4386.09, "samt":4386.09, "iamt":0, "csamt":0 }, { "itc_typ":"is", "camt":0, "samt":0, "iamt":0, "csamt":0 } ], "supp_rchrg_reg":[ { "itc_typ":"cg", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"ip", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"is", "camt":0, "samt":0, "iamt":0, "csamt":0 } ], "supp_rchrg_unreg":[ { "itc_typ":"cg", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"ip", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"is", "camt":0, "samt":0, "iamt":0, "csamt":0 } ] } }
Keeping in mind the following conditions: 1.If all the keys in the objects are 0 then the entire object will be removed (easy part). 2.If a key in the object has any value other than 0 , the object should not be removed and the key with "0" value should also be there.i've tried splitting value and using conditions to check for 0 or null values but the problem with that is it removes all keys that have 0 values thus failing condition 2 for the code. $vars = $data; $count = ""; $finalArray = array(); foreach ($vars as $keys => $values) { foreach ($values as $k => $v) { foreach ($v as $ke => $ve) { if ($keys == "table6") { $count = (array)$v; foreach ($count as $ck => $cv) { if ($cv != "0") { $flag = true; break; } } if($flag == false) { array_push($finalArray, $count); } } } } print_r($finalArray); die(); I expeced the output to contain the objects with key value pairs that does not contain 0 value but everything prints here. hi, i actually got some code working to add an ID dynamically to a website i'm working on (it was a momentous occasion ). here's the code: in the functions.php file: $url = 'tanzaniatravel.za.com'; $page = $_SERVER['PHP_SELF']; $page = str_replace("/","",$page); $page = str_replace(".php","",$page); $page = str_replace("$url", "", "$page"); i call the functions.php file into the index.php file, and add this as the opening body tag: Code: [Select] <body id="<?php echo $page; ?>"> this dynamically adds an ID named after whatever the actual page is named. now, i make use of the following top navigation structu Code: [Select] <ul class="nav-top"> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a class="nav-top-lineheight" href="index.php" title="Tanzania Travel home">Home</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a class="nav-top-lineheight" href="about.php" title="Why use TanzaniaTravel.Za.Com">Why us</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Overview and area map</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Tanzania National Park</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Tanzania Safari Lodges</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Tanzania Tour Itineraries</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Safari Dates & Prices</a></li> <li <?php echo ($page == '' ? 'class="nav-top-current"' : ''); ?>><a href="" title="">Zanzibar Kilimanjaro</a></li> <li class="<?php echo ($page == '' ? 'nav-top-current' : ''); ?> nav-top-last-li"><a class="nav-top-lineheight" href="" title="">Contact Us</a></li> </ul> you'll see that i've left the $page variable empty. i want that variable to call in the current page's ID, so that only the current page's <li> is active. this, of course, will greatly assist with developing the CSS for the navigation. i appreciate your help very much. thank you. Hello. I'm new to pHp and I would like to know how to get my $date_posted to read as March 12, 2012, instead of 2012-12-03. Here is the code: Code: [Select] <?php $sql = " SELECT id, title, date_posted, summary FROM blog_posts ORDER BY date_posted ASC LIMIT 10 "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $title = $row['title']; $date_posted = $row['date_posted']; $summary = $row['summary']; echo "<h3>$title</h3>\n"; echo "<p>$date_posted</p>\n"; echo "<p>$summary</p>\n"; echo "<p><a href=\"post.php?id=$id\" title=\"Read More\">Read More...</a></p>\n"; } ?> I have tried the date() function but it always updates with the current time & date so I'm a little confused on how I get this to work. |