Skip to content

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.

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…

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 =…