How can I check if 20 variables are all true, or if 20 variables are all false? if possible without using a really long if … the variables are actually array elements: array(‘a’=> true, ‘b’=> true …) to make it more clear: if the array has both true and false values r…
Tag: php
How to get complete current url for Cakephp
How do you echo out current URL in Cake’s view? Answer You can do either From a view file: Which will give you the absolute url from the hostname i.e. /controller/action/params Or which should give you the full url with the hostname.
Pass a variable to a PHP script running from the command line
I have a PHP file that is needed to be run from the command line (via crontab). I need to pass type=daily to the file, but I don’t know how. I tried: but this error was returned: Could not open input file: myfile.php?type=daily What can I do? Answer The ?type=daily argument (ending up in the $_GET array…
Replace spaces around hyphens with nbsp
I’m in need of (probably) regexp (or two) to do following: replace every space after any single letter word with I found this question, however, if there’s word with apostrophe (like there’s), previous regexp ‘thinks’ that the ‘s’ after the apostrophe is si…
How to run array_filter recursively in a PHP array?
Given the following array $mm When I run count(array_filter($mm)) I get 3 as result since it is not recursive. count(array_filter($mm), COUNT_RECURSIVE) also will not do because I actually need to run the array_filter recursively, and then count its result. So my question is: how do I recursively run array_fi…
Search Array : array_filter vs loop
I am really new in PHP and need a suggestion about array search. If I want to search for an element inside a multidimensional array, I can either use array_filter or I can loop through the array and see if an element matching my criteria is present. I see both suggestion at many places. Which is faster? Below…
Where should I store an encryption key for php?
I’m writing a php application that accepts sensitive customer data, and so I need to encrypt it before storing it in a mysql database. I’m going to use mysql’s built-in AES functionality to do column-level encryption. I want to avoid storing the encryption key on the server, and so i’m…
How to stop jQuery .ajax() execution when success is false?
I have this code which works. $.ajax({ type: “GET”, url: “includes/process.php”, data: “captcha=” + captcha, success: function(data) { if(data == ‘true’) …
How to ‘really’ detect integers from DB?
I’m trying to save some code with the following. I’ve an object with variables named the same as table rows so I could create an insert like this one: $query = “INSERT INTO table “; $columns =…
PHP: Regex match string not preceeded by a dollar sign
In my syntax highlighter, I use regex to parse different terms. Below is how I parse PHP classes: Now, just ignore the PHP class and the _getHtmlCode function. The regex, “/b{$class}b/”, matches names such as count. If I make a variable named $count, it matches that was well. How can I look for cl…