I need to check if there exists an instance of class_A ,and if there does exist, get that instance. How to do it in PHP? As always, I think a simple example is best. Now my problem has become: How to store the instance in a static member variable of class_A when instantiating? It’ll be better if the ins…
How to replace text over multiple lines using preg_replace
Hi have the following content within an html page that stretches multiple lines
Heading 1
Formulas to Calculate Geo Proximity
I need to implement a Geo proximity search in my application but I’m very confused regarding the correct formula to use. After some searches in the Web and in StackOverflow I found that the solutions are: Use the Haversine Formula Use the Great-Circle Distance Formula Use a Spatial Search Engine in the …
Doctrine – How to print out the real sql, not just the prepared statement?
We’re using Doctrine, a PHP ORM. I am creating a query like this: and then in the function I’m adding in various where clauses and things as appropriate, like this Later on, before execute()-ing that query object, I want to print out the raw SQL in order to examine it, and do this: However that on…
Passing parameters to PHPUnit
I’m starting to write PHPUnit tests and I’d like the tests to be run from developers machines as well as from our servers. Developers machines are set up differently than the servers and even …
The first day of the current month in php using date_modify as DateTime object
I can get the Monday of this week with: I would like to get with the same ease the 1st of this month. How can I achieve that? Answer Requires PHP 5.3 to work (“first day of” is introduced in PHP 5.3). Otherwise the example above is the only way to do it: In PHP 5.4+ you can do this:
Download of .zip file runs a corrupted file php
I’m trying to force a download of a protected zip file (I don’t want people to access it without logging in first. I have the function created for the login and such , but I’m running into a problem where the downloaded file is corrupting. Here’s the code I have: Here’s the error…
HTML coding and mixing of PHP or JavaScript code
I am assigned a task to revise a website and at present, I am working on index.html page. the previous coder has mixed a lot of JavaScript and CSS code in between and it is becoming difficult to read. …
Extract link attributes from string of HTML
What’s the best way to extract HTML out of $var? example of $var I want example: preg_match(); what else? Answer Instead of crafting long complicated regex, do it in steps one way of “non regex”, using explode
free lightweight template system
Is there any free, lightweight, non-MVC template systems made pure with PHP? I’m not interested in Smarty. Answer Sure: