php

Can I overload methods in PHP?

Example: I want to have two different constructors, and I don't want to use func_get_arg(), because then it's invisible what args are possible. Is it legal to write two of them, like: class MyClass { public function __construct() { // do something } public function __construct(array $arg) { // do something } } ...

Problem with converting from string to number

I have a variable $totalprice with number 1,072.00. If I use int($totalprice) or number_format($totalprice), it outputs 1.00. How can I solve this problem? I want 1072.00 ...

QA: Structure, Performance of this QueryBuilderClass

Hi there, I build this little helper class to try class chaining in PHP to build SQL (atm very simple SELECTs) queries very easily. Any ideas or complaints about it, or tips for the future? class SQLQueryBuilder{ public $query; public $parameters = array(); const SELECT = 'SELECT '; const FROM = ' FROM '; const WH...

Posible to make this Code smaller?

Hello everyone I have this Two Methods private function cacheAdd($id,$data) { $this->minicache->set($id,$data); } private function cacheGet($id) { return $this->minicache->get($id); } Each time if i want to check if the items are cached i have to do something like that: public function getFriendIds() { $info = $this->cach...

How to mark that an argument is optional in PHPDoc?

I've got this constructor that takes an optional argument. The main problem with this is usability. The developer using my framework will catch a headache instantly because he doesn't know if he can provide an argument, what kind of argument, or if he can't at all. Conclusion: It just sucks. But PHPDoc may help a little bit if someone ha...

Possible to clear cache of browser with php code?

I have a image upload tool written in php. Users may chose a file, and it gets uploaded with a certain filename, then if the user regrets chosing that file they may click the file-input and upload another file instead, BUT THE FILENAME IS THE SAME, so the browser caches the first image uploaded. And instead of the second image the brows...

adodb with sql server odbc connection problem

ADODB Error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified I downloaded the odbc driver for PHP. I pasted that driver in the PHP ext directory, then I get the error. Can anybody help me? ...

Background script on shared host with multiple PHP versions installed

I was needing a way to generate thumbnails (using PHP5) for an image management script and had a problem where my host has multiple versions of PHP installed (4 and 5), with PHP4 set as default. This meant that any calls to php from the CLI would run PHP4. I've come up with the following as what I hope to be a cross platform solution. I'...

Is this a proper way to use a class in PHP?

class MyImageTestClass{ var $url = "nfl2.jpg"; var $ID = "one"; function __construct() { } function setUrl($value){ $this->url = $value; } function setID($newid){ $this->ID = $newid ; } function loadImg($value,$newid){ $this->setID($newid); ...

Syntax problem with this short php code...

How should I write the $location variable into the header line? Right now it finds nothing... Blank adress bar... Here's what I have so far: $location='/ad?ad_id='.$id_nr; Header( "Location: $location" ); BTW, this is on my computer, virtual server, the adress is absolute! It works without the ?ad_id=.$id_nr part! ...

Place dots where a word is misspelled

Hello, I'm creating a web app in PHP where people can try to translate words they need to learn for school. For example, someone needs to translate the Dutch word 'weer' to 'weather' in English, but unfortunately he types 'whether'. Because he almost typed the right word, I want to give him another try, with dots '.' on the places wher...

Sending Web Page through Email in php

as in asp we have function to send complete web page in email, which basically save lot of time for developer in creating & sending email see the following code <% Set myMail=CreateObject("CDO.Message") myMail.Subject="Sending email with CDO" myMail.From="[email protected]" myMail.To="[email protected]" myMail.CreateMHTML...

Can I do timezone settings in a map with PHP?

I have a social network site I have been working on for a couple years in PHP/MySQL, I am now re-buidling the whole site from scratch again though. This time around I would really like to add in the ability for users to set a timezone for times on my site. So with that said, I am asking on a guide from start to finish of the steps I ne...

Will isset() return false if I assign NULL to a variable?

I mean... I "set" it to NULL. So isset($somethingNULL) == true? ...

How to make dot match newline characters using regular expressions

I have a string that contains normal characters, white charsets and newline characters between and . This regular expression doesn't work: /<div>(.*)<\/div>. It is because .* doesn't match newline characters. My question is, how to do this? ...

How to leverage PHP's autoloader functionality in such a way, that it searches through a defined set of paths?

One bad thing about using the autoloader is, that it doesn't know where to look at. My framework already has about 70 classes in about 15 different directories. Because of that, I didn't go for autoload, but instead struggle around with generating paths. So I have an associative paths array that give me paths from my root file to where I...

Collecting Stackoverflow Q and A's in a text file

I think my method is lame, but I cannot think of a better way to do this. I use Ultraedit text editor to hold all the stuff I cull out of Stackoverflow for PHP and MySQL in a text file. This is my strict format for each new entry: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ TITLE: THIS IS MY TITLE (ALL IN CAPS, FOLLOWD BY A DOTT...

Is there something to auto-include files other than classes in PHP?

The magic __autoload function works for classes only, right? How about other files like templates? I'd love to see a solution where I don't have to care at all about the big problem "where's the file? what's the path? when do I have to include it?". Would be a big time saver. Performance? Well... in this case I'd prefer faster developme...

Bulletproof method for listing folders in a specific directory (PHP 4 compatible)

I have a need for a simple function that lists all folders (non-recursive) in a given directory. The directory will always be the same (the images folder of my theme directory). I've been using the function below, but it fails when the PHP version is < 5. I suppose I could wrap the function in a PHP version check. I'm just trying to ma...

site wide contact form

I am using a contact form that was intially on just a couple of pages on mysite. Now we need to have it on all pages. The form is set up to only accept from whatever pages you define (which would be tedious and would have to include variables such as mysite.com and www.mysite.com) Is there a way to define excepting submission from all pa...