Rectangle 27 87

If you are using MySQL you can do it like this:

SELECT '2008-12-31 23:59:59' + INTERVAL 30 MINUTE;

For a pure PHP solution use strtotime

strtotime('+ 30 minute',$yourdate);

That MySQL trick is awesome. Never knew about that one.

adding 30 minutes to datetime php/mysql - Stack Overflow

php mysql datetime strtotime
Rectangle 27 4

Here's a PHP solution:

$day = Array('first','second','third','fourth','fifth','sixth','seventh',
             'eighth','ninth','tenth','eleventh','twelfth');
$gifts = Array('Twelve drummers drumming,',
               'Eleven pipers piping,',
               'Ten lords a-leaping,',
               'Nine ladies dancing,',
               'Eight maids a-milking,',
               'Seven swans a-swimming,',
               'Six geese a-laying,',
               'FIVE GOLDEN RINGS,',
               'Four calling birds,',
               'Three French hens,',
               'Two turtle doves, and',
               'A partridge in a pear tree');

for ($i = 0; $i < 12; ++$i) {
    printf("On the $day[$i] of Christmas my true love gave to me\n" . 
         implode("\n", array_slice($gifts,-($i+1))) . "\n\n");
}

language agnostic - Code Golf: Print the entire "12 Days of Christmas"...

language-agnostic code-golf rosetta-stone
Rectangle 27 19

If you'd like to have a PHP solution, you can try CssToInlineStyles.

that php script is well written. it doesn't handle the !important flag, but it's a nice script none the less.

What tools to automatically inline CSS style to create email HTML code...

html css email inline html-email
Rectangle 27 19

If you'd like to have a PHP solution, you can try CssToInlineStyles.

that php script is well written. it doesn't handle the !important flag, but it's a nice script none the less.

What tools to automatically inline CSS style to create email HTML code...

html css email inline html-email
Rectangle 27 4

Simple PHP solution for subdomains and multi-domain web apps

Step 1. Provide DNS A record as "*" for domains (or domain) you gonna serve "example.org"

A record => *.example.org
A record => *.example.net

Step 2. Check uniquity of logins when user registering or changing login. Also, avoid dots in those logins.

Step 3. Then check the query

// Request was http://qwerty.example.org
        $q = explode('.', $_SERVER['HTTP_HOST']);
        /*
            We get following array
            Array
            (
                [0] => qwerty
                [1] => example
                [2] => org
            )
        */

        // Step 4.
        // If second piece of array exists, request was for 
        // SUBDOMAIN which is stored in zero-piece $q[0]
        // otherwise it was for DOMAIN

        if(isset($q[2])) {
            // Find stuff in database for login $q[0] or here it is "qwerty"
            // Use $q[1] to check which domain is asked if u serve multiple domains
        }

?>
qwerty.example.org
qwerty.example.net 

johnsmith.somecompany.com
paulsmith.somecompany.com

If you need same nicks on different domains served differently, you may need to store user choise for domain when registering login.

smith.example.org // Show info about John Smith
smith.example.net // Show info about Paul Smith

How to let PHP to create subdomain automatically for each user? - Stac...

php subdomain
Rectangle 27 54

I was able to make the evil eye go away by simply adding this small header to the site in the IFrame (PHP solution):

header('P3P: CP="NOI ADM DEV COM NAV OUR STP"');

Remember to press ctrl+F5 to reload your site or Explorer may still show the evil eye, despite the fact that it's working fine. This is probably the main reason why I had so many problems getting it to work.

Edit: I found a nice blog entry that explains the problem with cookies in IFrames. It also has a quick fix in C# code: Frames, ASPX Pages and Rejected Cookies

IANAL, but the P3P policy seems to be legally binding. Are you aware what you're promising to the users here, or did you just mix tags until the EvilEye disappeared? I think browser caching won't be your biggest problem with these: "NOI: Web Site does not collect identified data. STP: Information is retained to meet the stated purpose. This requires information to be discarded at the earliest time possible. Sites MUST have a retention policy that establishes a destruction time table. The retention policy MUST be included in or linked from the site's human-readable privacy policy."

I must admit that I dont really care what it means, I just needed stuff to work in Explorer. The sites are our own non-public sites one of which uses a cookie to 'remember' which style to show the site in. So, yes, I just mixed tags until the evil eye disappeared.

The increasing irrelevance of P3P. cylab.cmu.edu/files/pdfs/tech_reports/CMUCyLab10014.pdf If it's so legally binding, there'd be lawsuit precedence by now proving such. It's viewed with such high esteem that all but one of my competitors even bother posting one in the first place. They must figure that if their customers can't leave the IE setting on Medium, they aren't worth the effort. Sales lost on one site would have to be pretty high if cookies don't work, the cart dies without them.

This answer suggests using a dummy header like CP="This_is_not_a_privacy_policy". Doing that seems less legally binding, I think (since e.g. NOI and STP and nothing like that at all is mentioned), and apparently makes IE happy :-)

Cookie blocked/not saved in IFRAME in Internet Explorer - Stack Overfl...

internet-explorer cookies privacy p3p
Rectangle 27 54

I was able to make the evil eye go away by simply adding this small header to the site in the IFrame (PHP solution):

header('P3P: CP="NOI ADM DEV COM NAV OUR STP"');

Remember to press ctrl+F5 to reload your site or Explorer may still show the evil eye, despite the fact that it's working fine. This is probably the main reason why I had so many problems getting it to work.

Edit: I found a nice blog entry that explains the problem with cookies in IFrames. It also has a quick fix in C# code: Frames, ASPX Pages and Rejected Cookies

IANAL, but the P3P policy seems to be legally binding. Are you aware what you're promising to the users here, or did you just mix tags until the EvilEye disappeared? I think browser caching won't be your biggest problem with these: "NOI: Web Site does not collect identified data. STP: Information is retained to meet the stated purpose. This requires information to be discarded at the earliest time possible. Sites MUST have a retention policy that establishes a destruction time table. The retention policy MUST be included in or linked from the site's human-readable privacy policy."

I must admit that I dont really care what it means, I just needed stuff to work in Explorer. The sites are our own non-public sites one of which uses a cookie to 'remember' which style to show the site in. So, yes, I just mixed tags until the evil eye disappeared.

The increasing irrelevance of P3P. cylab.cmu.edu/files/pdfs/tech_reports/CMUCyLab10014.pdf If it's so legally binding, there'd be lawsuit precedence by now proving such. It's viewed with such high esteem that all but one of my competitors even bother posting one in the first place. They must figure that if their customers can't leave the IE setting on Medium, they aren't worth the effort. Sales lost on one site would have to be pretty high if cookies don't work, the cart dies without them.

This answer suggests using a dummy header like CP="This_is_not_a_privacy_policy". Doing that seems less legally binding, I think (since e.g. NOI and STP and nothing like that at all is mentioned), and apparently makes IE happy :-)

Cookie blocked/not saved in IFRAME in Internet Explorer - Stack Overfl...

internet-explorer cookies privacy p3p
Rectangle 27 54

I was able to make the evil eye go away by simply adding this small header to the site in the IFrame (PHP solution):

header('P3P: CP="NOI ADM DEV COM NAV OUR STP"');

Remember to press ctrl+F5 to reload your site or Explorer may still show the evil eye, despite the fact that it's working fine. This is probably the main reason why I had so many problems getting it to work.

Edit: I found a nice blog entry that explains the problem with cookies in IFrames. It also has a quick fix in C# code: Frames, ASPX Pages and Rejected Cookies

IANAL, but the P3P policy seems to be legally binding. Are you aware what you're promising to the users here, or did you just mix tags until the EvilEye disappeared? I think browser caching won't be your biggest problem with these: "NOI: Web Site does not collect identified data. STP: Information is retained to meet the stated purpose. This requires information to be discarded at the earliest time possible. Sites MUST have a retention policy that establishes a destruction time table. The retention policy MUST be included in or linked from the site's human-readable privacy policy."

I must admit that I dont really care what it means, I just needed stuff to work in Explorer. The sites are our own non-public sites one of which uses a cookie to 'remember' which style to show the site in. So, yes, I just mixed tags until the evil eye disappeared.

The increasing irrelevance of P3P. cylab.cmu.edu/files/pdfs/tech_reports/CMUCyLab10014.pdf If it's so legally binding, there'd be lawsuit precedence by now proving such. It's viewed with such high esteem that all but one of my competitors even bother posting one in the first place. They must figure that if their customers can't leave the IE setting on Medium, they aren't worth the effort. Sales lost on one site would have to be pretty high if cookies don't work, the cart dies without them.

This answer suggests using a dummy header like CP="This_is_not_a_privacy_policy". Doing that seems less legally binding, I think (since e.g. NOI and STP and nothing like that at all is mentioned), and apparently makes IE happy :-)

Cookie blocked/not saved in IFRAME in Internet Explorer - Stack Overfl...

internet-explorer cookies privacy p3p
Rectangle 27 18

When you just want to execute one or several HTTP requests without having to wait for the response, there is a simple PHP solution, as well.

$socketcon = fsockopen($host, 80, $errno, $errstr, 10);
if($socketcon) {   
   $socketdata = "GET $remote_house/script.php?parameters=... HTTP 1.1\r\nHost: $host\r\nConnection: Close\r\n\r\n";      
   fwrite($socketcon, $socketdata); 
   fclose($socketcon);
}
// repeat this with different parameters as often as you like

On the called script.php, you can invoke these PHP functions in the first lines:

ignore_user_abort(true);
set_time_limit(0);

This causes the script to continue running without time limit when the HTTP connection is closed.

set_time_limit has no effect if php run in safe mode

asynchronous - Run PHP Task Asynchronously - Stack Overflow

php asynchronous background queue task
Rectangle 27 18

When you just want to execute one or several HTTP requests without having to wait for the response, there is a simple PHP solution, as well.

$socketcon = fsockopen($host, 80, $errno, $errstr, 10);
if($socketcon) {   
   $socketdata = "GET $remote_house/script.php?parameters=... HTTP 1.1\r\nHost: $host\r\nConnection: Close\r\n\r\n";      
   fwrite($socketcon, $socketdata); 
   fclose($socketcon);
}
// repeat this with different parameters as often as you like

On the called script.php, you can invoke these PHP functions in the first lines:

ignore_user_abort(true);
set_time_limit(0);

This causes the script to continue running without time limit when the HTTP connection is closed.

set_time_limit has no effect if php run in safe mode

asynchronous - Run PHP Task Asynchronously - Stack Overflow

php asynchronous background queue task
Rectangle 27 3

If you're looking for a PHP specific solution:

As mentioned in previous answers, the usual way is to use Apache's Rewrite Engine via the .htaccess file.

  • Redirect all incoming requests to a single PHP page.
  • On this page, firstly retrieve the URL entered using the pre-defined $_SERVER array, excluding the base URL. ($_SERVER["HTTPS"],$_SERVER['HTTP_HOST'],$_SERVER['REQUEST_URI'])
  • Once you have this, split up the URL into key and value pairs using the appropriate Regex. ('@/@')
  • Map the keys to keys of an array that stores page references.
  • Redirect to this page with POST or GET parameters of the values.

apache - Changing URL format in PHP - Stack Overflow

php apache .htaccess mod-rewrite url-rewriting
Rectangle 27 9

If you are on firefox install JSONovich. Not really a PHP solution I know, but it does the trick for development purposes/debugging.

I think this is the proper solution for when dev'ing an api. It gives the best of both worlds, easy debugging since you can read everything and you are not altering the backends behaviour, including its performance.

Agreed, it's nicely formatted with colours and collapsible too. Much nicer than you could hope to achieve with a bit of PHP

Pretty-Printing JSON with PHP - Stack Overflow

php json pretty-print
Rectangle 27 9

If you are on firefox install JSONovich. Not really a PHP solution I know, but it does the trick for development purposes/debugging.

I think this is the proper solution for when dev'ing an api. It gives the best of both worlds, easy debugging since you can read everything and you are not altering the backends behaviour, including its performance.

Agreed, it's nicely formatted with colours and collapsible too. Much nicer than you could hope to achieve with a bit of PHP

Pretty-Printing JSON with PHP - Stack Overflow

php json pretty-print
Rectangle 27 9

If you are on firefox install JSONovich. Not really a PHP solution I know, but it does the trick for development purposes/debugging.

I think this is the proper solution for when dev'ing an api. It gives the best of both worlds, easy debugging since you can read everything and you are not altering the backends behaviour, including its performance.

Agreed, it's nicely formatted with colours and collapsible too. Much nicer than you could hope to achieve with a bit of PHP

Pretty-Printing JSON with PHP - Stack Overflow

php json pretty-print
Rectangle 27 1

Here is a simple PHP solution:

header("Content-type:application/pdf");
// Set the name of the downloaded file here:
header("Content-Disposition:attachment;filename='example.pdf'"); 
 // Get the contents of the original file:
echo file_get_contents('example.pdf');

It contains only two headers. That should be enough in this case but if you need to set any additional information you are free to add more.

php - How to force a PDF download? - Stack Overflow

php jquery download
Rectangle 27 9

I've spent a bit of time loking into this, and the best solution that I've found was to install unoconv on the server, and using PHP to interface with it through system calls.

I would have loved to find a good native PHP solution for this, but unfortunately I couldn't.

I guess we need a dedicated hosting for installing Openoffice/unoconv on the server.

You would most likely need dedicated hosting, yes.

PHP Convert Word file to HTML without losing styling and images - Stac...

php ms-word docx doc
Rectangle 27 24

PHP 5.5+ two-line solution, using array_chunk and array_column:

$input  = '1-350,9-390.99';

$chunks = array_chunk(preg_split('/(-|,)/', $input), 2);
$result = array_combine(array_column($chunks, 0), array_column($chunks, 1));

print_r($result);
Array
(
    [1] => 350
    [9] => 390.99
)

How about case when input does not have value? For ex. $input = '1-,9-390.99';

[ 1 => '', 9 => '390.99' ]

php - Explode a string to associative array - Stack Overflow

php arrays
Rectangle 27 9

If you are on firefox install JSONovich. Not really a PHP solution I know, but it does the trick for development purposes/debugging.

I think this is the proper solution for when dev'ing an api. It gives the best of both worlds, easy debugging since you can read everything and you are not altering the backends behaviour, including its performance.

Agreed, it's nicely formatted with colours and collapsible too. Much nicer than you could hope to achieve with a bit of PHP

Pretty-Printing JSON with PHP - Stack Overflow

php json pretty-print
Rectangle 27 9

This is definitely possible. If you are looking for a pure php solution phing might be what you want. Also note that there's usually no reasons to build PHP scripts. They should 'just work'.

I realize they should "just work," but I am working as a php developer this summer and I am pretty sure that my employer use ant scripts to prepare an update for the live site so I was just wondering how they did it.

PHP is not used just for sites. If you have a whole unit-tested web application, with different configurations for different environments like developing, testing, and production, you should definitely use Phing or another build system. If there were no reason, Phing wouldn't exist... :)

Not counting on concatenating and minimizing css and javascript files, that is really a good use...

build PHP with ant scripts - Stack Overflow

php ant build
Rectangle 27 2

Another post on this topic with a nice jQuery/Ajax/PHP solution:

How to execute shell command in Javascript - Stack Overflow

javascript