I am reading a folder with lots of files. How can I get the creation date of a file. I don’t see any direct function to get it. There are filemtime and filectime. And if the file hasn’t been modified, what will happen? Answer Use filectime. For Windows it will return the creation time, and for Uni…
Tag: php
control file to PHP array
In Linux, .DEB files have ‘control’ text files that are arranged as follows: What is the best way to get the control file into a PHP array resembling: keeping in mind that the values can be multi-line and include the “:” separator. Thanks! Answer Implemented as described here: http://w…
Convert this array to an HTML List
I have this array: OR Every key is the id and value is the id for the childs of this parent. ID of 0 means that (3 & 6) have no parent. Now, i want to output an HTML list like: 3 4 7 8 9 5 6 Answer Test it. or
Email from PHP has broken Subject header encoding
My PHP script sends email to users and when the email arrives to their mailboxes, the subject line ($subject) has characters like a^£ added to the end of my subject text. This is obviously and …
How do I check if a string contains a specific word?
This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. Consider: Suppose I have the code above, what is the correct way to write the statement if ($a contains ‘are’)? Answer Now with PHP 8 you can…
PHP PDO: charset, set names?
I had this previously in my normal mysql_* connection: Do I need it for the PDO? And where should I have it? Answer You’ll have it in your connection string like: HOWEVER, prior to PHP 5.3.6, the charset option was ignored. If you’re running an older version of PHP, you must do it like this:
Preserve key order (stable sort) when sorting with PHP’s uasort
This question is actually inspired from another one here on SO and I wanted to expand it a bit. Having an associative array in PHP is it possible to sort its values, but where the values are equal to …
Email PDF Attachment with PHP Using FPDF
I want to email a PDF as an attachment that was created using FPDF. My code looks like this, but the attachment never comes through. Anyone familiar with doing this? I’m hoping to use the PHP mail() function. Answer This ended up working for me:
Setting up scripting and mysql database on separate servers
I have a unique setup for a web application that I need to get my head around. I have two servers that will need to talk to each other. Server A will host the actual PHP-based application; Server B will host the MySQL database and the server connection details. Server B will also be within a closed network, s…
PHP input sanitizer function?
What’s a method to sanitize PHP POST data for passing to a mail function? (I prefer a method that’s not part of the mysql_function() family of functions.) I take the data, sanitize it, print it back to the user and send it in an email to a preset address. EDIT: I’m just sending the email to …