php

PHP Get URL Contents And Search For String

In php I need to get the contents of a url (source) search for a string "maybe baby love you" and if it does not contain this then do x. ...

Design pattern for memcached data caching

It's easy to wrap optional memcached caching around your existing database queries. For example: Old (DB-only): function getX x = get from db return x end New (DB with memcache): function getX x = get from memcache if found return x endif x = get from db set x in memcache return x end The th...

Making an Image Greyscale with GD Library

My mission is to create a little app where you can upload a picture, and the app will turn it into ASCII art. I'm sure these exist already but I want to prove that I can do it myself. This would involve taking an image, making it greyscale and then matching each pixel with a character depending on how dark the picture is and how full th...

How do I catch a PHP Fatal Error

I can use set_error_handler() to catch most PHP errors, but it doesn't work for fatal (E_ERROR) errors, such as calling a function that doesn't exist. Is there another way to catch these errors? I am trying to call mail() for all errors and am running PHP 5.2.3. ...

Increase days to php current Date()

How do I add a certain number of days to the current date in PHP? I already got the current date with: $today = date('y:m:d'); Just need to add x number of days to it ...

Is there an easy way to convert a number to a word in PHP?

In PHP, is there an easy way to convert a number to a word? For instance, 27 to twenty-seven. ...

Shouldn't mysql_real_escape_string() leave slashes in Database?

Hello Im using smarty and mysql_real_escape_string() for user input, and when I insert some code with ' or " , and lookup in phpmyadmin it shows without backslashes. When I get record from DB i doesn't have backslashes also. But when I just pass escaped string without inserting into the db it is backslashed. Shouldn't it add slashes, ...

strtolower on passing a session to a variable, is that legal?

Is it alright to do this? $author = strtolower($_SESSION['valid_username']); I want to enter all authors into the table as lower case. ...

How can I get PHPUnit MockObjects to return differernt values based on a parameter?

I've got a PHPUnit mock object that returns "return value" no matter what its arguments: // From inside a test... $mock = $this->getMock('myObject', 'methodToMock'); $mock->expects($this->any)) ->method('methodToMock') ->will($this->returnValue('return value')); What I want to be able to do is return a different value based ...

Is it possible to rewind a PDO result?

I'm trying to write an iterator for results from a PDO statement but I can't find any way of rewinding to the first row. I would like to avoid the overhead of calling fetchAll and storing all the result data. // first loop works fine foreach($statement as $result) { // do something with result } // but subsequent loops don't foreac...

PHP5: calling external functions, and logging errors

I'm painfully new to PHP, and was trying to set up phpBB on my local site. I have a stock debian install of apache2 and php5. The phpBB installer ran fine, connected to the database and created all its tables with no problem. But when I tried to open the login page, I got a 0-byte response. A little digging showed that it was never m...

A tidy way to clean your URL variables?

I'm wondering if there is a quick and easy function to clean get variables in my url, before I work with them.( or $_POST come to think of it... ) I suppose I could use a regex to replace non-permitted characters, but I'm interested to hear what people use for this sort of thing? ...

How to set the default location of the FCKEditor file browser?

I'm working the the image upload piece of the FCKEditor and I've got the uploading working properly but am stuck with the server file browser. You can see in the dialog above has a Browse Server button which pops up the following dialog The problem is that I have no idea which folder the file browser is pointing at. I've set the U...

Calling java from PHP exec

Hello, I am doing the following in PHP: exec('java -jar "/opt/flex3/lib/mxmlc.jar" +flexlib "/opt/flex3/frameworks" MyAS3App.as -default-size 360 280 -output MyAS3App.swf'); When I run this from the command line, it runs fine and finishes in a second or two. When I run this command from PHP exec, the java process takes 100% CPU and ...

Why do I need to use a popular framework?

I've been a PHP developer for many years now, with many tools under my belt; tools that I've either developed myself, or free-to-use solutions that I have learned to trust. I looked into CodeIgniter recently, and discovered that they have many classes and helper routines to aid with development, yet saw nothing in the examples that I co...

Deploy PHP using Git

How can I deploy a PHP website using Git? I have a hunch it has something to do with using git hooks to perform a git reset --hard on the server side, but how would I go about accomplishing this? ...

UTF-8 all the way through...

I'm setting up a new server, and want to support UTF-8 fully in my web application. I have tried in the past on existing servers and always seem to end up having to fall back to ISO-8859-1. Where exactly do I need to set the encoding/charsets? I'm aware that I need to configure Apache, MySQL and PHP to do this - is there some standard c...

How to invoke a C# web service through PHP?

I've written a web service using ASP.NET (in C#) and I'm attempting to write an example PHP client using NuSOAP. Where I'm tripped up on are examples of how to do this; some show soapval being used (and I don't quite understand the parameters - for example passing false as string types, etc.), while others are just using straight arrays...

How do I resize pngs with transparency in PHP?

I'm attempting to resize pngs with transparent backgrounds in PHP and the code samples I've found online don't work for me. Here's the code I'm using, advice will be much appreciated! $this->image = imagecreatefrompng($filename); imagesavealpha($this->image, true); $newImage = imagecreatetruecolor($width, $height); // Make a new trans...

phpunit avoid constructor arguments for mock

What is the way to avoid phpunit having to call the constructor for a mock object? Otherwise I would need a mock object as constructor argument, another one for that etc. The api seems to be like this: getMock($className, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, ...