Something, I think Apache, adds these HTTP headers to all responses generated by PHP scripts: Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 This works ok for actual dynamic pages, but I have some page that, while generated by PHP, are most…
PHP substring extraction. Get the string before the first ‘/’ or the whole string
I am trying to extract a substring. I need some help with doing it in PHP. Here are some sample strings I am working with and the results I need: I want to get the string till the first /, but if no / is present, get the whole string. I tried, I think it says – get the position
PHP comments: # vs. //
Lately I’ve been using # instead of // for doing single line comments inside my code. However, I see most of the people prefer //. Is there a particular reason for preferring them instead of #? Performance? File weight? Anything? Answer It doesn’t change a single thing, I’d say ; it’s …
PHP: What is the fastest and easiest way to get the last item of an array?
What is the fastest and easiest way to get the last item of an array whether be indexed array , associative array or multi-dimensional array? Answer prints “1”
What exactly are late static bindings in PHP?
What exactly are late static bindings in PHP? Answer You definitely need to read Late Static Bindings in the PHP manual. However, I’ll try to give you a quick summary. Basically, it boils down to the fact that the self keyword does not follow the same rules of inheritance. self always resolves to the cl…
$date + 1 year?
I’m trying to get a date that is one year from the date I specify. My code looks like this: It’s returning the wrong date. Any ideas why? Answer To add one year to todays date use the following: For the other examples you must initialize $StartingDate with a timestamp value for example: Try this o…
Can’t save php.ini
I have PHP for FastCGI installed on Windows 7 through the Web Platform Installer. I need to edit php.ini to enable logging, but I’m not able to overwrite the existing file, apparently because …
PHP preg_replace non-greedy trouble
I’ve been using the following site to test a PHP regex so I don’t have to constantly upload: http://www.spaweditor.com/scripts/regex/index.php I’m using the following regex: /(.*?).{3}/ on the …
Is there a way to redefine a type hint to a descendant class when extending an abstract class?
I will be using the following example to illustrate my question: class Attribute {} class SimpleAttribute extends Attribute {} abstract class AbstractFactory { abstract public function update(…
PHP output to command line
I start my script from command line and it outputs things as they happen but a week ago it stopped outputing and now outputs everything when script finishes. I have ob_start() but as I know this does not effect command line output. Answer You need to remove ob_start()… try this code on the command line,…