php

PHP: Caching ordered integer partition algorithm

Hello! First: The problem's name in Wikipedia is "ordered partition of a set". I have an algorithm which counts possible partitions. To speed it up, I use a cache: function partition($intervalSize, $pieces) { // special case of integer partitions: ordered integer partitions // in Wikipedia it is: ordered partition of a set global $...

PHP Function to bend/warp an image.

I'm working with my simple PHP captcha algorithm (http://www.source.ofitall.com/devel/captcha.php) and I have been struggling to try and adjust it to be the more attractive and easier to read, Google style captcha. Does anyone know of a function that will take in a GD image reference and bend/warp it, Google style? ...

php code for each wordpress widget?

I'm currently changing my theme and I need each individual code of each widget. For example I need the rss widget, or categories widget or comment widget, etc. I want those widget integrated in my footer. Where can I see the code? I have no idea where to begin look... ...

What is the best way to split a string into an array of Unicode characters in PHP?

In PHP < 6, what is the best way to split a string into an array of Unicode characters? If the input is not necessarily UTF-8? I want to know whether the set of Unicode characters in an input string is a subset of another set of Unicode characters. Why not run straight for the mb_ family of functions, as the first couple of answers did...

Do PHP opcode cache work with __autoload?

Sorry if this is basic, I am trying to learn as much as I can about OO in PHP and I am slowly learning how to use it (very limited). So I am wanting to know if __autoload() has any affect on PHP opcode cache's? ...

Detecting if two number ranges clash

This is hopefully a very simple maths question. If I have two number ranges, what is the simplest and most efficient way to check if they clash, eg: 10-20 and 11-14 // clash as B is contained in A 11-15 and 20-22 // don't clash 24-26 and 20-30 // clash as A is contained in B 15-25 and 20-30 // clash as they overlap at each end I curre...

Telephone user identification process

I have no idea where to start so apologies for what might be a vague question. I would like a telephone verification system like elance.com where a user gets a telephone call, and has to either input the numbers displayed on his computer screen, or he has to type in the numbers spoken to him on the phone. I need this as I want my appli...

How to implement "Maintenance Mode" on already established website

I have built a fairly robust website (PHP) with more than 60 pages. I have only now realized (unfortunately) that I should have built in an "In Maintenance Mode" feature to allow an admin to temporarily disable the website and point it to a Maintenance Mode page. This would only allow those logged in as an admin to view the website. T...

How to convert array to SimpleXML in PHP

I was wondering if anyone knew how to convert an array to a Simplexml object in PHP. Thanks ...

Use web interface to modify htaccess file

The solution to a previous question (How to implement “Maintenance Mode” on already established website), was to use a modified .htaccess to deny IP addresses. What is the best way to use a web interface to modify an .htaccess file? What I want is a way for an admin to log in to the admin area and switch Maintenance Mode on and off usi...

Alternative authentication sources in CakePHP (LDAP)

I'm working on a CakePHP project and am currently building the user authentication part of it. The problem is that my authentication information (ie: the passwords) are not stored in my database -- the authentication source is LDAP but my question applies equally to any non-database source. It appears as though Cake only handles passwor...

Changing drupal view filter from greater than to less than

I have a drupal view I've created for events, each event has a date field I'd like to create a way either in the view itself or via the API to have an option for users to select all events, past events or future events. I've created a basic filter event_date > now which works, however I can't seem to change this to event_date < now via t...

Stream FTP download to output

I am trying to stream/pipe a file to the user's browser through HTTP from FTP. That is, I am trying to print the contents of a file on an FTP server. This is what I have so far: public function echo_contents() { $file = fopen('php://output', 'w+'); if(!$file) { ...

PHP: Allow users to make posts with certain tags

Users on my site can post news items. But right now, it's all honor system as far as HTML goes. function postNewsItem($subject, $body, $userid){ $time = time(); $subject = mysql_real_escape_string($subject); $body = mysql_real_escape_string($body); $q = "INSERT INTO news (subject, body, userid) VALUES ('$subject', '$body', '$use...

PHP Curl: read incrementally

I have a PHP script that's supposed to take in a URL and search a database for a cached version of the URL. If it finds it, it prints out the cached version to the user, otherwise it downloads it using cURL and echos it to the user. Currently, the downloading script looks something like this: // create a new cURL resource $ch = curl_i...

How can I ignore time for NOW()?

I have a mysql database of entries with dates. So what I want is to show all the dates in my database and then under each date, I want to show all the entries in the database entered on the specefic date. I am thinking of two loops but I don't know how to write the condition to display all the dates in my database befo...

Calculating time blocks from given date range

I'm trying to calculate time blocks from given date range. Here's my attempt: <?php class timeRangeCalculator { /** * Start time of block * * @var DateTime */ private $blockStart; /** * Block duration in seconds * * @var int */ private $blockDuration; /** * Start of range * * @var DateTime ...

How can I get a variable from one form into a javascript popup window?

Using the code below, I'd like to post or get the value returned (date) into a javascript window so that I can run a query off of the value. Can someone please tell me how to do this? <form method="post" action="search.html"> <p style="padding:10px;"> <input type="text" id="date" name="date" value="" maxlength="10"><a href="javasc...

how do I make this function a class?

hi everybody, i've been creating functions for too long without taking my code to 'classes'. I learn well through example and I just wanted to convert this simple function into a class so I can compare something I know with something I don't... Take the following function: function affiliateName($affiliateID) { $sql = 'SELECT * FROM ...

Combine 2-3 transparent PNG images on top of each other with PHP

I am working on a custom avatar system for a project, but I have never really done much with the image side of PHP. I assume I need to use GD in some way, but I have no idea where to even start. Basically, there are a bunch of pre-made transparent PNG images. Users can select 2-3 of them to customize their avatar, and I want to be abl...