php

Magic __get getter for static properties in PHP

public static function __get($value) does not work, and even if it did, it so happens that I already need the magic __get getter for instance properties in the same class. This probably is a yes or no question, so, it is possible? ...

How can I dynamically add input fields to a form?

I'm not much of a web programmer, but I'm creating a simple web app that has a form where the user can enter a series of points (x,y,z) but I don't know how many the user is going to enter. I don't want to guess the probable maximum (100 maybe?) and put 100 fields on the form because it would look ugly. What's the easiest way to add more...

Select multiple options by default using object_select_tag

I am running Symfony 1.2 and utilizing the object helper to create some inline editable fields outside of a form. Because there is no symfony or scriptalicious short cut to create an inline edit tag for multiple choice select boxes (much like input_in_place_editor_tag or Ajax.InPlaceCollectionEditor), I am using object_select_tag with t...

PHP fsockopen() / fread() returns messed up data

I read some URL with fsockopen() and fread(), and i get this kind of data: <li 10 ></li> <li 9f >asd</li> d <li 92 Which is totally messed up O_O -- While using file _ get _ contents() function i get this kind of data: <li></li> <li>asd</li> Which is correct! So, what the HELL is wrong? i tried on...

Question about image thumbnail performance in PHP

I have a function in PHP that resizes images into a thumbnail, my image upload script takes an uploaded image and runs this function to resize the image if it is wider then 700px it then also runs the function 2 more times to create 2 different sized thumbnail images, so there is a total of 3 images saved each time a user uploads an imag...

To strip whitespaces inside a variable in PHP

How can you strip whitespaces in PHP's variable? I know this comment PHP.net. I would like to have a similar tool like tr for PHP such that I can run simply tr -d " " "" I run unsuccessfully the function php_strip_whitespace by $tags_trimmed = php_strip_whitespace($tags); I run the regex function also unsuccessfully $tags_trimmed...

PHP + MySQL software

Hi guys. Need your suggestion on php/mysql software. I develop PHP websites using Dreamweaver, I also have to use phpmyadmin, sql query editor (to work with database) and WinSCP (to upload/backup files over SFTP). Could you suggest me please some software which contains all in one (PHP syntax highlighting, db connections and running sql...

To make `no-variable` if-clause in PHP

How can you make the if -clause which do this and this if there is no variable in the URL by PHP? there is no variable which has value in the URL by PHP? Examples of the URLs which should be true for the if -clause for #1: www.example.com/index.php example.com/index.php example.com/index.php? Examples of the URLs which should be t...

How to run code upon class definition (not object instantiation)

I'm looking for a way to transparently run code when a class is defined - more importantly, when the class is extended. For example, if I have: class A { function define() { echo "A has been defined!\n"; } __magicDefine { define(); } } class B extends A { } I'd like that to print "A has been defined!\n". Is this i...

strange behaviour on php

Can some one please tell me why I get odd results rurning the following code? <?php class Bank { var $ID; var $balance; var $name; function bank($name,$id,$balance=0) { $this->ID=$id; $this->balance=$balance; $this->name=$name; } function getBalance() { return $this->balance; } ...

Whats the best way to output data from a database using php?

I'm relatively new to php, and I'm working on a project using a mysql database. The project consists of users being able to write posts, which are then shown in a list format. The problem is, the posts are shown in different locations on the site, like the index (main) page, and the users profile page. Similar to twitter if you're confus...

How to set a timeout on PHP5 curl calls? Published CURL options do not seem to work...

We've written a script that pulls data from an external server. If the server goes down we don't want our server waiting for the data since we process a lot of data and we don't want it bogged down. To address this, we're trying to timeout our curl calls if they take more than a couple hundred milliseconds. I found some documentatio...

HTML tables to PDF in PHP - neither DOMPDF nor html2ps/pdf are working

For the longest time now I've been trying to convert HTML pages containing large tables to PHP. These are styled with CSS and can be several pages long. I first tried DOMPDF. It works great, until a document is more than one page. None of the fixes I've found work. Either it errors out, or any element that would be even partially on the...

php methods defined outside class?

Hello there I am wondering if php methods are ever defined outside of the class body as they are often done in C++. I realise this question is the same as http://stackoverflow.com/questions/71478/defining-class-methods-in-php . But I believe his original question had 'declare' instead of 'define' so all the answers seem a bit inappropr...

How to get started on a diet logging script in php/mysql/jquery

Hey guys, hope this isn't too much of a n00b question I'm mainly a front end developer that has recently started to do some back end programming. The script I'm working on is pretty simple (in theory). I just don't know where to begin and was hoping for some advice that will lead me in the right direction. -The script is essentially a ...

To put an array to a WHERE -clause in PHP without hitting X times Postgres

How can you put an array to the WHERE -clause below without creating 50 pg_execute -commands in PHP / PostgreSQL? // to get the question_ids of the newest questions $result_q_id = pg_prepare($dbconn, "query6", "SELECT question_id FROM questions ORDER BY was_sent_at_time DESC LIMIT 50;" ); ...

Does php execution stop after a user leaves the page?

I want to run a relatively time consuming script based on some form input, but I'd rather not resort to cron, so I'm wondering if a php page requested through ajax will continue to execute until completion or if it will halt if the user leaves the page. It doesn't actually output to the browser until a json_encode at the end of the file...

Imagemagick not installing with MAMP

So I read this article on how to install Imagemagick with MAMP, and did exactly how it said, (sudo port install Imagemagick, everything installed okay, then change the envvars file), yet I still get this error when trying to run a script that uses it: Fatal error: Class 'Imagick' not found in /Applications/MAMP/htroots/active/includes/i...

Extending PHP static classes

I've been struggling in this area for days now, and I have reached a conclusion, but since the conclusion was not what I was looking for, before I give up, I'll try to see what other people say. Faith dies last... Let's say we have a superclass (called "Super") and a subclass (called "Sub"). class Super { protected static $title = ...

How do you just get the vars in a url using php?

I have a url, example.com/?/page1 and i want to find out what the GET part of the url is, for example: ?/page1 how do i do this? like, without having to split strings and stuff? ...