I have several date ranges in form of DateTime $begin, DateTime $end. Those ranges can overlap in every possible way: etc. What I am trying to do is to get length (in seconds or DateInterval) of those ranges between start of the first one and the end of the latest one (fourth in the case above), excluding reg…
PHP Convert Windows-1251 to UTF 8
I have a small html code and I need to convert it to UTF-8. I use this iconv(“windows-1251”, “utf-8”, $html); All text converts correctly, but if text for example in tag …, then …
utf8 not showing hyphens correctly in echoed text
my MySQL database is set to utf8_unicode_ci and I have $pdo->exec(‘SET NAMES “utf8″‘) as part of the following php code yet when I echo text from the query a hyphen – looks likes this –. What am I …
WordPress database error MySQL server has gone away for query
I get this error so frequently that the php_error log file increases 1MB every 2 seconds. and the site is very slow. I have tried to add this line to wp-db.php but it did not help. The web server is IIS 7, latest version of mysql and wordpress Answer This trick will work for all WordPress versions. Open your …
Php foreach – separating each loop with comma except the last element
Heres what i mean: current output would be: i want the output to be like this: (all ‘a’ separated with comma and when it comes to the last loop it doesnt write a comma) Answer Try this:
Find difference between two datetimes and format at Y-m-d H:i:s
I’m trying to get the difference between two datetimes and return it as a datetime. I’ve found examples using diff but I can’t seem to get it right. However $totaltime logs 0000-00-00 00:00:00 to my DB. Is this because I’m not formatting my totaltime variable? Answer I’m not sure…
How to return a line number in a PHP script
Is it possible for a PHP script to return a line number in which some command is called? I’m having trouble describing what I want so maybe an example. I have PHP code that calls MySQL on many occasions. In line 49 is: The text “line 49” I wrote manually. Is it possible to get this number &#…
Add a new index to multidimensional array
I have a multidimensional array. ie. Array ( [0] => Array ( [item_id] => 1 [item_name] => x ) [1] => Array ( […
Get insert_id for all rows inserted in single mysqli query (multiple values)
Working in PHP and using MYSQLI. Trying to get the insert_id for all rows inserted from a single insert query with multiple values. Keeping it in a single call for efficiency. My actual code has hundreds of values in one insert query. However, here is some sample code for an insert with just 4 values: The abo…
how to upload an image on ACF with update_field on wordpress
I have a form, which has an upload ($_FILES[‘watch_photo’]) field. I have looked around and came to put this function together. It basically takes all relevant information so it is re-usable in the future, it will return an array of the $pid, and URL of the file, when it is done. The problem is th…