Skip to content

Tag: php

Cakephp: how to pass values into a javascript file?

I have some javascript that is being included in a view and I used inkedmn’s method in this thread: adding-page-specific-javascript-to-each-view-in-cakephp So I now have the following code in my view: But I need to pass some values from the view into the javascript file and I’m unsure of how to ac…

How to set UTF-8 encoding for a PHP file

I have a PHP script called : http://cyber-flick.com/apiMorpho.php?method=getMorphoData&word=kot That displays some data in plain text: As you can see in place of proper chars there are so “bushes”. What i would like to do is display this in a way so that people see in browser proper UTF-8 char…

htaccess access to file by ip range

How to allow access to file only to users with ip which are in a range of ip addresses? For example file admin.php. and range from 0.0.0.0 to 1.2.3.4. I need configure access to only ONE file not to directory. Answer Just add a FilesMatch or Files directive to limit it to a specific script. The following woul…

Problem with COPY FROM with PHP in postgresql

I have some big .csv files and I am trying to put it into database. I am using this construction: But after use i function in CLI I got that: This is not a problem with end marker, but with encoding. If I open this file in VIM and will save it again, everything is OK, but without this operations

Creating an array from a string separated by spaces

I have an input where a user may type in multiple words, and they are told to separate it with a space. So input may look like this: or like this: How can I check for spaces, and if there are spaces, split the words, then put it all into an array? I’ll loop through that array in my program.

Vimeo video link regex

Anybody got the regex for vimeo video links to extract them from a pragraph for use in php? Can’t seem to find a proper one for the latest vimeo url scheme Answer As far as I can tell, the scheme is just http://vimeo.com/A_NUMBER, so try http://(www.)?vimeo.com/(d+). If you don’t need links to be …

Can you Create your Own Hook in Drupal?

Is it possible to create your own hook in a Drupal module for other Drupal modules to consume? If not, is there a mechanism in Drupal for third party developers to provide hooks? If everything’s been a no so far, where in the core are the list of hooks implemented? As I understand things, Drupal modules…

Bulk Rename Files in a Folder – PHP

I have 1000 images in a Folder, which has SKU# word in all the images. For examples what i need to do is read all the filenames and rename it to the following So remove SKU# from filename, is it possible in PHP to do bulk renaming ? Answer Yeah, just open the directory and create a loop to access

Replace string in an array with PHP

How can I replace a sub string with some other string for all items of an array in PHP? I don’t want to use a loop to do it. Is there a predefined function in PHP that does exactly that? How can I do that on keys of array? Answer But array_map is just a hidden loop. Why not use