Skip to content

Tag: php

$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 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,…

Get parent directory of running script

In PHP, what would be the cleanest way to get the parent directory of the current running script relative to the www root? Assume I have: $_SERVER[‘SCRIPT_NAME’] == ‘/relative/path/to/script/index….

Cannot use string offset as an array in php

I’m trying to simulate this error with a sample php code but haven’t been successful. Any help would be great. “Cannot use string offset as an array” Answer For PHP4 …this reproduced the error: For PHP5 …this reproduced the error: (From bugs.php.net actually) Edit, so why d…

How to use XMLReader in PHP?

I have the following XML file, the file is rather large and i haven’t been able to get simplexml to open and read the file so i’m trying XMLReader with no success in php I’ve unfortunately not found a good tutorial on this for PHP and would love to see how I can get each element content to s…