php-5.3

Find first free date in agenda

江枫思渺然 提交于 2019-12-11 12:06:52
问题 in my component I have created an agenda, where user can save their appointments. Agenda table is quite simple: there is a title, description and start/end datetime fields. When a user adds a new event, I'd wish to hint him with the first empty spot. How can I achieve that? Is that possible with a single/bunch queries, or I have to create a loop until I find the first empty spot? For example this is my table: | ID | Start date | End date | | 1 | 2012-06-14 09:00:00 | 2012-06-14 09:32:00 | | 2

Php 5.3 magick quotes gpc

喜欢而已 提交于 2019-12-11 08:35:31
问题 I have a problem, an old program with mysql querys doesn't works in new php 5.3 with magick_quotes_gpc disabled, when a variable of query have single quote, ex: $text=$_GET['text'] --> "This is a text doesn'**strong text**t works" mysql_query("UPDATE table SET '{$text}'"); Only works if I make previously this: $text=mysql_real_escape_string($_GET['text']); But I can't modify the program, and the program is to big and have a lot of querys, which I can i do? 回答1: But I can't modify the program,

How to access array index when using explode() in the same line?

允我心安 提交于 2019-12-11 03:15:48
问题 Can't wrap my head around this... Say, we explode the whole thing like so: $extract = explode('tra-la-la', $big_sourse); Then we want to get a value at index 1: $finish = $extract[1]; My question is how to get it in one go, to speak so. Something similar to this: $finish = explode('tra-la-la', $big_sourse)[1]; // does not work Something like the following would work like a charm: $finish = end(explode('tra-la-la', $big_sourse)); // or $finish = array_shift(explode('tra-la-la', $big_sourse));

DateTime in php with timezone

徘徊边缘 提交于 2019-12-11 02:42:12
问题 I have a question. I try to use datetime in php. I did : $now = new \DateTime(); When I print_r the $now I have : DateTime Object ( [date] => 2016-12-01 05:55:01 [timezone_type] => 3 [timezone] => Europe/Helsinki ) When I look at clock I have 16:05 . I need to set the timezone ? I want to use Bucharest timezone. How I can get the right date and hour ? Thx in advance 回答1: You have two ways to set right timezone. It is object way and procedural way. Examples Object $datetime = new DateTime();

PHP lambda functions and scope

一个人想着一个人 提交于 2019-12-11 02:20:35
问题 The below function takes an array and checks to see if its keys and values match the specified datatypes. I seem to be having some problems with the internal lambda functions that were previously working. I'm running PHP v5.3.6. They last worked under v5.3.4. They are complaining that the non-passed variable is not in scope. If I restate that variable as global then the error goes away, but the variable is empty. /** * @param array $arr, array to be tested * @param mixed $keytype * @param

Sum elements from multimendion array by key

半腔热情 提交于 2019-12-10 23:36:18
问题 I want to sum all elements from my array based on column I try to make this sum but not expected results. My array : Array ( [0] => Array ( [Periode] => 2008/2009 [Producteurs] => 2 [Sucreries] => 0 [Papeteries] => 0 ) [1] => Array ( [Periode] => 2008/2009 [Producteurs] => 0 [Sucreries] => 0 [Papeteries] => 5 ) [2] => Array ( [Periode] => 2008/2009 [Producteurs] => 0 [Sucreries] => 14 [Papeteries] => 0 ) [3] => Array ( [Periode] => 2009/2010 [Producteurs] => 2 [Sucreries] => 0 [Papeteries] =>

PHP crypt function on different OS

微笑、不失礼 提交于 2019-12-10 20:43:33
问题 In my php application I use the php crypt() function where my salt value is the first two characters from the username. I noticed that the function returns a different result on windows and linux. I also read on w3cschools that this function behaves different on different operating systems. It is possible to configure the php environment in order to obtain the same result on both operating systems? (Modifying the encryption mode is not an option.) 回答1: crypt() uses whatever underlying hash

what does & do in php

三世轮回 提交于 2019-12-10 20:11:58
问题 I have this code $myNewClass->cars =& Orders_Car::GetRecords($myNewClass->searchString); ^ what is & doing there. thanks 回答1: Read Do not use PHP references by PHP expert Johannes Schlüter PHP references are a holdover from PHP 4, where objects were passed by value instead of by reference unless you deliberately made them by reference. This isn't necessary when using PHP 5, because all objects are passed by reference in PHP 5 all the time. Scalars and arrays are still passed by value by

Static Inheritance prior to PHP 5.3

前提是你 提交于 2019-12-10 18:06:29
问题 class A { static $v = "A"; static function echoExtendedStaticVariable() { echo self::$v; } } class B extends A { static $v = "B"; // override A's variable with "B" } Why does: echo B::$v print "A"? And how do I get it to print "B"? Is there a way to do this before PHP 5.3? 回答1: B->echoExtendedStaticVariable() == 'A' because self:: is evaluated at compile-time , not run-time. It's as if you wrote A:: instead of self:: . What you want is a feature called "late static binding"--it's "late"

Using PHP 5.3 ?: operator

别来无恙 提交于 2019-12-10 14:16:23
问题 With this test page: $page = (int) $_GET['page'] ?: '1'; echo $page; I don't understand the output I'm getting when page is undefined: Request Result ?page=2 2 ?page=3 3 ?page= 1 ? error: Undefined index page Why the error message? It's PHP 5.3; why doesn't it echo "1"? 回答1: The proper way (in my opinion) would be: $page = isset($_GET['page']) ? (int) $_GET['page'] : 1; Even if you used the new style, you would have problems with ?page=0 (as 0 evaluated to false). "New" is not always better..