Is there a way to write the PHP file_exists function so that it searches a directory for a file with an arbitrary extension. For instance, suppose I knew that a file were called “hello”, but I didn’t know the extension, how would I write a function that searched for a file called hello.* and…
Call private methods and private properties from outside a class in PHP
I want to access private methods and variables from outside the classes in very rare specific cases. I’ve seen that this is not be possible although introspection is used. The specific case is the next one: I would like to have something like this: This method should be able to be injected in the code l…
What is mod_php?
While going through a Zend tutorial, I came across the following statement: Note that the php_flag settings in .htaccess only work if you are using mod_php. Can someone explain what that means? Answer mod_php means PHP, as an Apache module. Basically, when loading mod_php as an Apache module, it allows Apache…
How to prefix a positive number with plus sign in PHP
I need to design a function to return negative numbers unchanged but should add a + sign at the start of the number if its already no present. Example: It will get only numeric input. This function is going to be called several times in echo/print so the quicker the better. Answer You can use regex as: But I …
What is the scope of require_once in PHP?
Simple question: Is the scope of require_once global? For example:
Using fopen and str_replace to auto fill a select option
I have this file ‘gardens.php’, which pulls data from a table called ‘generalinfo’ and I use fopen to send that data to a file called ‘index.html’. Here is the issue, only one option is filled. I have a demo running here Garden Demo <– this is a new updated page an…
How to sort files by date in PHP
I currently have a script which allows me to output the list of files inside the same directory. The output shows the names, and then I used filemtime() function to show the date when the file was modified. How will I sort the output to show the latest modified file? This is what I have for now: Answer You ne…
How can I encrypt a cookie value?
How can I encrypt, and later decrypt, a cookie value in PHP? How secure will the encryption be? Answer I can not simply think of a situation where encrypting data in the cookie is useful. If you want to retain secret data about the user or his preferences, information, whatever, then store it on the server in…
Loading HTML dynamically using JavaScript and PHP
I have the following code: Some html… Other html…
Help Reading Binary Image Data from SQL Server into PHP
I cannot seem to figure out a way to read binary data from SQL server into PHP. I am working on a project where I need to be able to store the image directly in the SQL table, not on the file system. Currently, I have been using a query like this one: INSERT INTO myTable(Document) SELECT * FROM OPENROWSET(BUL…