php

PHP define scope for included file

I have quite a lot of PHP view files, which I used to include in my controllers using simple include statements. They all use methods declared in a view class which they get like $view->method(); However I recently decided that it would be better if the including would also be done by this view class. This however changes the scope of th...

how could I combine these regex rules?

I'm detecting @replies in a Twitter stream with the following PHP code using regexes. $text = preg_replace('!^@([A-Za-z0-9_]+)!', '<a href="http://twitter.com/$1" target="_blank">@$1</a>', $text); $text = preg_replace('! @([A-Za-z0-9_]+)!', ' <a href="http://twitter.com/$1" target="_blank">@$1</a>', $text); How can I best combine thes...

Where can I find the code CD for my Kindle Edition of PHP and MySQL Web Development, 4th Ed?

I just bought PHP and MySQL Web Development 4th Edition by Welling and Thompson. The book uses examples from the CD-ROM, which appears to not come with the Kindle Edition. Is there any way to download, legally or questionably, the CD that contains the code samples? I'm finding the book really useful, but don't want to manually type in al...

What is the scale of PHP's circular reference problem and should I worry about it?

If I am using a tree structure of nodes similar to the code below, do I have to worry about the circular reference? I have read that PHP uses a memory allocation mechanism which can make life very hard for the garbage collector when there are circular references involved. What I want to know is: If my tree consists of only a few n...

javascript or php - what is most efficient for updating?

I have several update methods in a javascript file, used for updating my ajax application, like so: function updateByPk(layer, pk) { url = "get_auction.php?cmd=GetAuctionData&pk="+pk+"&sid="+Math.random(); update(layer, url); } function updateByQuery(layer, query) { url = "get_records.php?cmd=GetRecordSet&query="+query+"&sid=...

deleting mysql records with ajax

I would like to know the best way to delete records from a live database and refresh the page instantly. At the moment I am using ajax, with the following javascript method: function deleterec(layer, pk) { url = "get_records.php?cmd=deleterec&pk="+pk+"&sid="+Math.random(); update('Layer2', url); } if cmd=deleterec on the php pag...

Getting a PDO query string with bound parameters without executing it

Is it possible to get a query string from a PDO object with bound parameters without executing it first? I have code similar to the following (where $dbc is the PDO object): $query = 'SELECT * FROM users WHERE username = ?'; $result = $dbc->prepare($query); $username = 'bob'; $result->bindParam(1, $username); echo $result->queryString; ...

Is it possible to replace (monkeypatch) PHP functions?

You can do this in Python, but is it possible in PHP? >>> def a(): print 1 ... >>> def a(): print 2 ... >>> a() 2 e.g.: <? function var_dump() {} ?> Fatal error: Cannot redeclare var_dump() in /tmp/- on line 1 ...

best way to create/split string to tags

In my php application user able to enter the tags(like here while ask question). I assume it will be regexp, and I used one - mb_split('\W+', $text) - to split by non-word characters. But I want to allow users to enter characters like "-,_,+,#" etc which are valid ones to be in url and are common. Is there exiting solutions for this...

What's the state of TDD and/or BDD in PHP?

How widespread, supported, developed is testing in the PHP world? On par with Java? Up there with Ruby/Rails? I Googled and found that testing frameworks exist but I'm wondering if they're widely used. Do the major PHP IDE's have built-in test runners the way Eclipse's Java tools do or NetBeans's Ruby/Rails tools do? Is testing built i...

How can I unserialize session data to an arbitrary variable in PHP?

I want to unserialize a session_encode()'d string of session data to my own array (i.e. not to $_SESSION.) There doesn't appear to be an in-built function that handles this. There's session_decode() but it writes directly to the $_SESSION super-global. There's unserialize() but it returns false on session_encode()'d strings as they're...

PHP Thumbnails

I was looking at a way to dynamically create thumbnails using PHP and GD but everytime i select a large image maybe 10MegaPixels about 4-5MB it gives the error **images/Surabhi_Cow.jpgimages/tn/Surabhi_Cow.jpg Fatal error: Allowed memory size of 31457280 bytes exhausted (tried to allocate 10368 bytes) in C:\Program Files\xampp\htdocs\My...

Any way to force download a remote file?

Im looking to add a "Download this File" function below every video on one of my sites. I need to force the user to download the file, instead of just linking to it, since that begins playing a file in the browser sometimes. The problem is, the video files are stored in a remote server. Any way I can force the download in php? ...

How can I generate Dynamic Javascript?

I render a page using YUI. and depending on the user I need to change how it is rendered. This change is not something that can be parametrized, it is drastic and different for each user. Please tell me how can I generate Javascript dynamically? ...

jQuery forms.js with multiple forms per page

I would like to submit information to a mySql database using php and ajax. The page that the info is being sent from (form.php) has multiple forms that are generated from a "while()" loop. On success, I would a response to update a div above the particular form from which the data was submitted. I am currently using jQuery and the jqu...

[PHP] ORM Query results: Arrays vs Result handle wrapped in Iterator interface

Okay, here's one for the pro's: For a couple of years now, i've been working on my own PHP ORM/ActiveRecord implementation that i named Pork.dbObject. It's loosly based on the 'make your own site with rails in 5 minutes' movie we all saw a couple of years ago. You can do things like: $clients = dbObject::Search("Client", array("ID > 5...

Where can I find videos of someone (who knows what they're doing) writing PHP ?

Its been YEARS since I did any PHP. I am working in .NET but supposed to be teaming up with some PHP people. I'd really like to get up to speed a little in whats changed in the language and the IDE tools - but I really don't have the time nor energy to learn anything. I probably won't have to write any PHP, but I want to. I'm looking t...

mysql multi-column search

I have a table like this: +-------------------+---------------+ | description | colour | +-------------------+---------------+ | Macrame Dress | Washed Black | | Darcelle Gilet | Dirty Shellac | | Darcelle Cardigan | Washed Black | | Let It Rot Vest | Optic White | | Let It Rot Crew | Washed Black | | Let It...

How can I give a large number of class methods "almost" the same code

hello I have this PHP class class myclass{ function name($val){ echo "this is name method and the value is".$val; } function password($val){ echo "this is password method and the value is".$val; } } and here is how to use it: $myclass= new myclass(); $myclass->name("aaa")//...

What are the best practices to speed up site development with CMS?

How can I speed up site development with a particular CMS if I need to build a lot of sites? Should I prepare a few different solutions based on barebone CMS but with pre-built components and deploy them if similar site is being requested for production? Or should I use some solution generator like Joomla-Builder? Are there any tools fo...