-
Who's Online 2 Members, 1 Anonymous, 49 Guests (See full list)
All Activity
- Past hour
-
Your wording and examples are a bit all over the place, I believe you're trying to filter an array, and then manipulate any specific ones that match particular date. Right? So, if 5/5/25 is a day with a special rate, and is within the date range provided by the user, use the "special" price? You can use array_map to manipulate the items that match a specific date. An example of it being used for only one "special" date - May 5 2025 $dates = [ '2025-05-01', '2025-05-02', '2025-05-03', '2025-05-04', '2025-05-05', ]; $specialDate = '2025-05-05'; $specialPrice = 8.00; // The special price to apply ONLY on $specialDate $priceUpdateCallback = function ($item) use ($specialDate, $specialPrice) { $element = ["date" => $item, "price" => 10]; if ($item == $specialDate) { $element['date'] = $specialDate; $element['price'] = $specialPrice } return $element; }; $result = array_map('priceUpdateCallback', $dates); echo "<pre>", print_r($result), "</pre>"; Should give you something like Array ( .............Array ( [date] => 2025-05-05 [price] => 8 ) )
-
for the posted information, the requested date range of 2025-05-06 to 2025-05-22 doesn't match any of the $seasonPrices data. It starts one day after the end of the May Day range and ends one day before the start of the Summer half-term range. it should use the base/default price for every day. since you are using a standard date format, you can directly perform date comparisons by order, as mentioned in the previous thread. you can directly compare a date to the $seasonPrices SeasonStart and SeasonEnd values to find if it is between a date range. i would write a function/class-method that accepts a date input, loops over the $seasonPrices data, returns the first price that is between the SeasonStart and SeasonEnd values, or returns zero (or some other easily detected value) if it reaches the end without finding a match. as a procedural function, something like - function get_price($date,$seasonPrices) { foreach($seasonPrices as $row) { // date between start and end if($row->SeasonStart <= $date && $date <= $row->SeasonEnd) { return $row->SeasonPrice; } } // no match return 0; }
- Today
-
I am trying to get values from an array with a date range This is the var_dump assuming from date is 06 May 2025 and to date is 22 May 2025 [0]=> string(10) "2025-05-06" [1]=> string(10) "2025-05-07" [2]=> string(10) "2025-05-08" [3]=> string(10) "2025-05-09" [4]=> string(10) "2025-05-10" [5]=> string(10) "2025-05-11" [6]=> string(10) "2025-05-12" [7]=> string(10) "2025-05-13" [8]=> string(10) "2025-05-14" [9]=> string(10) "2025-05-15" [10]=> string(10) "2025-05-16" [11]=> string(10) "2025-05-17" [12]=> string(10) "2025-05-18" [13]=> string(10) "2025-05-19" [14]=> string(10) "2025-05-20" [15]=> string(10) "2025-05-21" [16]=> string(10) "2025-05-22" It then searches the following array $count = 0; foreach($seasonPrices as $row) { $price[$count]['name'] = $row->SeasonName; $price[$count]['days'] = implode(',', Cal::bookedArray($row->SeasonStart, $row->SeasonEnd)); $price[$count]['price'] = $row->SeasonPrice; $count++; } unset($count); [2]=> array(3) { ["name"]=> string(16) "Spring half-term" ["days"]=> string(120) "2025-02-21,2025-02-22,2025-02-23,2025-02-24,2025-02-25,2025-02-26,2025-02-27,2025-02-28,2025-03-01,2025-03-02,2025-03-03" ["price"]=> string(3) "100" } [3]=> array(3) { ["name"]=> string(6) "Easter" ["days"]=> string(186) "2025-04-11,2025-04-12,2025-04-13,2025-04-14,2025-04-15,2025-04-16,2025-04-17,2025-04-18,2025-04-19,2025-04-20,2025-04-21,2025-04-22,2025-04-23,2025-04-24,2025-04-25,2025-04-26,2025-04-27" ["price"]=> string(3) "100" } [4]=> array(3) { ["name"]=> string(7) "May Day" ["days"]=> string(43) "2025-05-02,2025-05-03,2025-05-04,2025-05-05" ["price"]=> string(3) "110" } [5]=> array(3) { ["name"]=> string(16) "Summer half-term" ["days"]=> string(109) "2025-05-23,2025-05-24,2025-05-25,2025-05-26,2025-05-27,2025-05-28,2025-05-29,2025-05-30,2025-05-31,2025-06-01" ["price"]=> string(3) "110" } [6]=> array(3) { ["name"]=> string(6) "Summer" ["days"]=> string(505) "2025-07-18,2025-07-19,2025-07-20,2025-07-21,2025-07-22,2025-07-23,2025-07-24,2025-07-25,2025-07-26,2025-07-27,2025-07-28,2025-07-29,2025-07-30,2025-07-31,2025-08-01,2025-08-02,2025-08-03,2025-08-04,2025-08-05,2025-08-06,2025-08-07,2025-08-08,2025-08-09,2025-08-10,2025-08-11,2025-08-12,2025-08-13,2025-08-14,2025-08-15,2025-08-16,2025-08-17,2025-08-18,2025-08-19,2025-08-20,2025-08-21,2025-08-22,2025-08-23,2025-08-24,2025-08-25,2025-08-26,2025-08-27,2025-08-28,2025-08-29,2025-08-30,2025-08-31,2025-09-01" ["price"]=> string(3) "120" } [7]=> array(3) { ["name"]=> string(16) "Autumn half-term" ["days"]=> string(120) "2025-10-24,2025-10-25,2025-10-26,2025-10-26,2025-10-27,2025-10-28,2025-10-29,2025-10-30,2025-10-31,2025-11-01,2025-11-02" ["price"]=> string(3) "110" } [8]=> array(3) { ["name"]=> string(10) "Christmas " ["days"]=> string(186) "2025-12-19,2025-12-20,2025-12-21,2025-12-22,2025-12-23,2025-12-24,2025-12-25,2025-12-26,2025-12-27,2025-12-28,2025-12-29,2025-12-30,2025-12-31,2026-01-01,2026-01-02,2026-01-03,2026-01-04" ["price"]=> string(3) "120" } [9]=> array(3) { ["name"]=> string(16) "Spring half-term" ["days"]=> string(109) "2026-02-20,2026-02-21,2026-02-22,2026-02-23,2026-02-24,2026-02-25,2026-02-26,2026-02-27,2026-02-28,2026-03-01" ["price"]=> string(3) "100" } [10]=> array(3) { ["name"]=> string(6) "Easter" ["days"]=> string(197) "2026-04-02,2026-04-03,2026-04-04,2026-04-05,2026-04-06,2026-04-07,2026-04-08,2026-04-09,2026-04-10,2026-04-11,2026-04-12,2026-04-13,2026-04-14,2026-04-15,2026-04-16,2026-04-17,2026-04-18,2026-04-19" ["price"]=> string(3) "100" } [11]=> array(3) { ["name"]=> string(7) "May Day" ["days"]=> string(43) "2026-05-01,2026-05-02,2026-05-03,2026-05-04" ["price"]=> string(3) "110" } [12]=> array(3) { ["name"]=> string(16) "Summer half-term" ["days"]=> string(109) "2026-05-22,2026-05-23,2026-05-24,2026-05-25,2026-05-26,2026-05-27,2026-05-28,2026-05-29,2026-05-30,2026-05-31" ["price"]=> string(3) "110" } [13]=> array(3) { ["name"]=> string(6) "Summer" ["days"]=> string(516) "2026-07-17,2026-07-18,2026-07-19,2026-07-20,2026-07-21,2026-07-22,2026-07-23,2026-07-24,2026-07-25,2026-07-26,2026-07-27,2026-07-28,2026-07-29,2026-07-30,2026-07-31,2026-08-01,2026-08-02,2026-08-03,2026-08-04,2026-08-05,2026-08-06,2026-08-07,2026-08-08,2026-08-09,2026-08-10,2026-08-11,2026-08-12,2026-08-13,2026-08-14,2026-08-15,2026-08-16,2026-08-17,2026-08-18,2026-08-19,2026-08-20,2026-08-21,2026-08-22,2026-08-23,2026-08-24,2026-08-25,2026-08-26,2026-08-27,2026-08-28,2026-08-29,2026-08-30,2026-08-31,2026-09-01" ["price"]=> string(3) "120" } [14]=> array(3) { ["name"]=> string(16) "Autumn half-term" ["days"]=> string(120) "2026-10-23,2026-10-24,2026-10-25,2026-10-25,2026-10-26,2026-10-27,2026-10-28,2026-10-29,2026-10-30,2026-10-31,2026-11-01" ["price"]=> string(3) "110" } [15]=> array(3) { ["name"]=> string(10) "Christmas " ["days"]=> string(186) "2026-12-18,2026-12-19,2026-12-20,2026-12-21,2026-12-22,2026-12-23,2026-12-24,2026-12-25,2026-12-26,2026-12-27,2026-12-28,2026-12-29,2026-12-30,2026-12-31,2027-01-01,2027-01-02,2027-01-03" ["price"]=> string(3) "120" } If the requested dates are present in the price array i then need to extract the price for each day to put into an array to calculate the total cost if(in_array($rested, $prices) { array_push($cost, $prices[]['price']; } echo array_sum($cost); I have tried for loops, for each loops, array_diff, array_intersect and anything else i could think of put cant get it to work properly. Any help would me much appreciated The code i have put isnt the exact code i have now as i have been trying all day and its changed every time i've tried something else. The code i have right now only adds 2 prices to the cost array even though there more than 2 dates in the requested dates Please Help!! Thanks in advance
-
I managed to sort it, my question was a bit misleading. I had a calendar that was only showing 1 booked date range but that was because i had used = instead of == so now it shows all bookings
-
I realised I should add…. I have actually also established that this is unlikely to be a php (or more generally a ‘dynamically created content’) issue. I tried converting some of my files into statically generated files, ie nothing to do with PHP. My XSL files were still not cached by the browser properly. So this issue right now actually seems unrelated to PHP. It’s some kind of inconsistency between browsers’ treatment of different file types.
- Yesterday
-
Remilo9868 joined the community
-
marvia joined the community
- Last week
-
Thank you @gizmola - appreciate your time to reply. Unfortunately don’t have a Mac, but will looked into getting some help with this and also the “tail” suggestion .
-
DigitizingBuddy joined the community
-
There are a few different ways to process the stats based on what game and mod you are running. The one that is giving me the error is based on savestate 1 which continues from the last saved game log file. Savestate 0 runs without errors, but processes every game log file all over again every time. This is the from the batch file I use to tun the stats: C:\xampp\php\php.exe -f "C:\xampp\htdocs\q3eplus.servequake.com\vsp.php" -- -l q3a-xp -p savestate 1 "D:\Quake III Arena\excessiveplus\logs\server_mp.log"
-
Suyadi's comment is factually accurate. The code expects the constant value LOG_READ_SIZE, and it is not defined. WIth that said, often utility applications come with instructions on how they should be configured, it looks like this might be the case for the application. Check instructions and see if there is a configuration file that needs to exist in a particular place. Many applications are distributed with a file with default settings that needs to be copied and renamed.
-
That means it's not defined anywhere on that file so PHP can't find it. My suggestion would be to raise this issue to the developer of that script as the developer seems forgot to define that constant in their code. Those LOG_READ_SIZE constant used to set the offset of the fseek() and we don't know how big he set those number. my wild guess is as big as the log file size, so: defined('LOG_READ_SIZE') or define('LOG_READ_SIZE', filesize($logfilePath)); $seekResult = fseek($parser->logFileHandle, -LOG_READ_SIZE, SEEK_CUR);
-
Invalid password when using password_verify
Suyadi replied to rwahdan1978's topic in PHP Coding Help
This is correct, the length of string produced by password_hash() with default algorithm (bcrypt, as of now) is always 60 characters. So if you do password_hash('mypassword', PASSWORD_DEFAULT); and your database column can only store less than 60 characters, it will be truncated with some error being thrown -
Lol, me too That should be: $sql = $pdoObject->prepare($qry); $result = $sql->execute(['exp' => null, 'email' => $myusername]); As the PDOStatement::execute only accept one parameter. Reference: https://www.php.net/manual/en/pdostatement.execute.php
-
Trying to use GLOB function to create gallery.
Suyadi replied to BluApple's topic in PHP Coding Help
HI, you can try to use glob() with the __DIR__ constant. For example: $currentDir = __DIR__; // this is your current directory So, if you want to scan images inside your sub-directory, let's say the 'gallery' directory, just do: $subDirectory = 'gallery'; $images = glob($currentDir . '/' . $subDirectory . '/*.{jpg,jpeg,gif,png,bmp,webp}', GLOB_BRACE); Check the result: print_r($images); -
$timezone = 'Asia/Jakarta'; // Change this $dbTime = '2025-04-26 20:30:00'; $dbTime = DateTime::createFromFormat('Y-m-d H:i:s', $dbTime, new DateTimeZone($timezone)); $now = new DateTime('now', new DateTimeZone($timezone)); print_r($dbTime->diff($now)); print_r($now->diff($dbTime)); Result: DateInterval Object ( [y] => 0 [m] => 0 [d] => 5 [h] => 2 [i] => 13 [s] => 10 [f] => 0.828 [invert] => 0 [days] => 5 [from_string] => ) DateInterval Object ( [y] => 0 [m] => 0 [d] => 5 [h] => 2 [i] => 13 [s] => 10 [f] => 0.828 [invert] => 1 [days] => 5 [from_string] => )
-
How to get the current time and add 10 minutes?
Suyadi replied to rwahdan1978's topic in PHP Coding Help
$timezone = 'Asia/Jakarta'; // Change this $date = new DateTime('now',new DateTimeZone($timezone)); $date->modify('+10 minute'); echo $date->format('Y-m-d H:i:s'); -
Suyadi joined the community
-
Trying to use GLOB function to create gallery.
BluApple replied to BluApple's topic in PHP Coding Help
Adding question marks helped! Silly me! 😧 Using barands code displays all picures on the smae page while i'm trying to create a folder. Http://inflorescence.infy.uk/tryout.php -
Trying to use GLOB function to create gallery.
BluApple replied to BluApple's topic in PHP Coding Help
The file is in the main folder where to upload the website. Let me try to use the correct inclusief code. That might help. I'll get back as soon as i've tried that. -
I'm using a game stats processor called VSP stats which parses game logs and displays the output to a web page. The issue I'm having is that it stops processing the logs with the following error: PHP Fatal error: Uncaught Error: Undefined constant "LOG_READ_SIZE". The line of code that is causing the error: $seekResult = fseek($parser->logFileHandle, -LOG_READ_SIZE, SEEK_CUR); Server is on Windows 11 Apache 2.4.58 PHP 8.2.12.
-
janampatri joined the community
-
what exactly is the single $booked data for vs the array of $bookings? i have the following recommendations - use a standard yyyy-mm-dd date format. if/when you store the data in a database, this will be necessary to allow queries to compare dates by order. it will also make your current code easier to understand. the bookings data should be stored in a database table. you should have a start_date and an end_date input to the code on this page, so that the code will work for any date range, from multiple years down to a single month. you are looping over the $res array for every date being displayed, currently for the whole year. i recommend that you instead produce an array using the date as the array index, and the stored value indicating what is occurring on that date, limited to be between the start_date and end_date mentioned above. as you are producing the output, you can simply test, no loop required, if there is an entry in this array, using isset(), then get the stored value if there is one, and use it to control what you output for the date. with a little conditional logic, you don't need separate logic to deal with the first (partial) week, then repeat that logic for the remainder of each month. if you use php's short-open-print tag and leave out the ; right before a closing tag, you can use simple syntax like - <?=$some_var?> to output values in the markup. use php's DateInterval and DatePeriod to expand the booking date ranges. here's example code for item #7 - $start = new DateTime($start); $end = new DateTime($end); $end = $end->modify('+1 day'); // include the end point $interval = new DateInterval('P1D'); // 1 day $daterange = new DatePeriod($start, $interval ,$end); $dates = array(); foreach($daterange as $date){ $dates[] = $date->format("Y-m-d"); }
-
Trying to use GLOB function to create gallery.
Psycho replied to BluApple's topic in PHP Coding Help
First, your two includes at the top and bottom of the page are not within correct PHP tags. Need a ? before the starting PHP. The DIV in your code is in the HTML source, but there is nothing within it. That would seem to indicate that there was no content in the $images array. I'm guessing that the path you provided to the glob function is not correct. Where is the 'photography' folder in relation to where the php file is being executed? -
In a past life, have experience turning dynamic, user generated content via a web page into print-ready PDFs for commercial printing. In that case, the user input on the web forms was converted into PostScript code that was then run through a processing engine (my expertise was in the postscript programming). So, when I had a need to generate PDFs as a PHP hobbyist, I looked for a solution where I could "program" the creation of the PDF in the same way as I did with PostScript. I ended up using the FPDF Library. If you have fairly rigid constraints on the layout of the content, this could be an option. Instead of generating an HTML page and running that through something to convert it to a PDF, this library allows you to create a PFD file in much the same way you would create a web page. I.e. determine "where" on the page you want to put an element, define things like color, font, and then place the elements on the page. However, there is another, simpler option. Instead of emailing the user a PDF, just send the user a link. That link would be to a web page of their quote and then the user can print the web page quote to PDF, the printer, or however they want. I think most shopping sites I use have this approach if I want to print the invoice. This much simpler and less moving parts, IMO.
-
Trying to use GLOB function to create gallery.
BluApple replied to BluApple's topic in PHP Coding Help
-
Trying to use GLOB function to create gallery.
gizmola replied to BluApple's topic in PHP Coding Help
When people are using tutorials to try and create PHP based features, there are pitfalls, the potential for misunderstandings and the possibility of error. We need to see what your actual code is. The only exception is in the case of passwords, keys etc. Those should be replaced. So we would need to see your code and the actual path you used in your code. The operating system, hosting location etc, is also important information in many cases. It sounds like you have error turned off at present, and for development, errors need to be turned on, so you can see what they are. It looks like your code has one or more errors in it, and that is why you are getting a blank page, but if errors are turned off, you can't see what the error message is. -
Trying to use GLOB function to create gallery.
BluApple replied to BluApple's topic in PHP Coding Help
Thank you Barand! It still gives a blank page though. -
I'm Trying to create a booking/availability calendar that shows a full 12 months bookings/availability. I have come up with the following so far $publicHolidays = array(date('j-n-Y', strtotime('1st January 2025')), date('j-n-Y', strtotime('18th April 2025')), date('j-n-Y', strtotime('21st April 2025')), date('j-n-Y', strtotime('5th May 2025')), date('j-n-Y', strtotime('26th May 2025')), date('j-n-Y', strtotime('25th August 2025')), date('j-n-Y', strtotime('25th December 2025')), date('j-n-Y', strtotime('26th December 2025'))); $bookings = array(array('Check-In' => '1-1-2025', 'Check-Out' => '7-1-2025'), array('Check-In' => '3-2-2025', 'Check-Out' => '13-2-2025'), array('Check-In' => '2-3-2025', 'Check-Out' => '25-3-2025'), array('Check-In' => '2-4-2025', 'Check-Out' => '21-4-2025'), array('Check-In' => '6-6-2025', 'Check-Out' => '9-6-2025'), array('Check-In' => '2-9-2025', 'Check-Out' => '5-9-2025'), array('Check-In' => '3-11-2025', 'Check-Out' => '30-11-2025')); foreach($bookings as $row) { $res[] = Cal::bookedArray($row['Check-In'],$row['Check-Out']); } $booked = Cal::bookedArray('1-4-2025','7-4-2025'); $month = '1'; $year = date('Y'); for($m=$month;$m<13;$m++) { $timestamp = mktime(0, 0, 0, $m, 1, $year); $daysInMonth = date("t", $timestamp); $firstDay = date("N", $timestamp); if($m == date('m')) { $featured =' featured'; } else { $featured=''; } ?> <div class="col-xl-4 col-lg-6" data-aos="fade-up" data-aos-delay="100"> <div class="pricing-item p-0<?php echo $featured;?>"> <h3 class="mb-0 pt-5"><?php echo date('F', mktime(0,0,0,$m)); ?></h3> <table class="table table-bordered m-0"> <tr> <th>Mon</th> <th>Tue</th> <th>Wed</th> <th>Thu</th> <th>Fri</th> <th>Sat</th> <th>Sun</th> </tr> <?php $dayCount = 1; ?> <tr> <?php for ($i = 1; $i <= 7; $i++) { $date = "$dayCount-$m-$year"; if ($i < $firstDay) { echo "<td></td>"; } else { $date = "$dayCount-$m-$year"; if(date('l', strtotime($date)) == 'Saturday' && !in_array($date, $booked)) { $cellBg="class='table-info'"; } elseif(date('l', strtotime($date)) == 'Sunday' && !in_array($date, $booked)) { $cellBg="class='table-info'"; } elseif(in_array($date, $publicHolidays) && !in_array($date, $booked)) { $cellBg="class='table-warning'"; } else { $cellBg="class='table-light'"; } foreach($res as $key => $val) { /* $firstday = reset($val); $lastday = end($val); if($date = $firstday) { $cellBg="class='table-primary'"; } elseif(in_array($date, array_splice($val,1,-1))) { $cellBg="class='table-danger'"; } elseif($date = $lastday) { $cellBg="class='table-primary'"; } */ if(in_array($date, array_splice($val,1,-1))) { $cellBg="class='table-danger'"; } } echo "<td $cellBg>$dayCount</td>"; $dayCount++; } } echo "</tr>"; while ($dayCount <= $daysInMonth) { echo "<tr>"; for ($i = 1; $i <= 7 && $dayCount <= $daysInMonth; $i++) { $date = "$dayCount-$m-$year"; if(date('l', strtotime($date)) == 'Saturday' && !in_array($date, $booked)) { $cellBg="class='table-info'"; } elseif(date('l', strtotime($date)) == 'Sunday' && !in_array($date, $booked)) { $cellBg="class='table-info'"; } elseif(in_array($date, $publicHolidays) && !in_array($date, $booked)) { $cellBg="class='table-warning'"; } else { $cellBg="class='table-light'"; } foreach($res as $key => $val) { /* $firstday = reset($val); $lastday = end($val); if($date = $firstday) { $cellBg="class='table-primary'"; } elseif(in_array($date, array_splice($val,1,-1))) { $cellBg="class='table-danger'"; } elseif($date = $lastday) { $cellBg="class='table-primary'"; } */ if(in_array($date, array_splice($val,1,-1))) { $cellBg="class='table-danger'"; } } echo "<td $cellBg>$dayCount</td>"; $dayCount++; } ?> </tr> <?php } ?> </table> </div> </div> <?php } Its reading the arrays, drawing the calendar and colorizing the weekends, public holidays and bookings. What i need is to change the check-in and check-out date color to reflect what they are. I've commented out what ive been trying but it isnt working. here is the bookedarray function if anyone needs it public static function bookedArray($strDateFrom,$strDateTo) { $aryRange = []; $iDateFrom = strtotime($strDateFrom); $iDateTo = strtotime($strDateTo); if ($iDateTo >= $iDateFrom) { array_push($aryRange, date('j-n-Y', $iDateFrom)); // first entry while ($iDateFrom<$iDateTo) { $iDateFrom += 86400; // add 24 hours array_push($aryRange, date('j-n-Y', $iDateFrom)); } } return $aryRange; } Any help would be much appreciated or even a pointer as to were I could find a solution Thanks in advance
-
Trying to use GLOB function to create gallery.
Barand replied to BluApple's topic in PHP Coding Help
<?php $images = glob("path/to/folder a/*.*"); foreach ($images as $i) { echo "<img src='$i'>"; }