php

How do I find my server's IP address in PHP(CLI)

Aside from the obvious (localhost, 127.0.0.1) does PHP (command line interface!) have a mechanism for discovering the IP of the computer the script is running on? $SERVER[] will not work as this is not a Web app - this is a command line script. TIA ...

Make output an object array

<?php //example code $url = 'http://clients1.google.com/complete/search?hl=en&amp;q=speed'; function processURL( $url ) { $contents = file_get_contents( $url ); return $contents; } print_r( processURL($url) ); ?> Output: window.google.ac.h(["speed",[["speed test","89,300,000 results","0"],["speed channel","76,100,000 results"...

Calculate greatest number of days between two consecutive dates

If you have an array of ISO dates, how would you calculate the most days between two sequential dates from the array? $array = array('2009-03-11', '2009-03-12', '2009-04-12', '2009-05-03', '2009-10-30'); I think I need a loop, some sort of iterating variable and a sort. I can't quite figure it out. This is actually being output from M...

interface vs abstract class

In php :: Please explain when i should use interface and when i should use abstract class? And how i can change my abstract class in to an interface? ...

Selecting specific values in a DB (sorta...)

Ok, I had a hard time coming up with a title, as you can probably tell. Anyway, I need to select 5 items from a DB excluding the first one. More specifically, I have items in a DB, each with a specific, auto-incrementing ID. I need to select the first 5 after the item with the highest ID. What would be the best way to do this? Thanks! -...

foreach and multidimensional arrays

I am trying to make some table out of a multidimensional array here is my code http://pastebin.com/d13d62098 I am getting this error **Warning: Invalid argument supplied for foreach() here is an example of the array www.pastebin.com/m3454956a any ideas? ...

Why is my time() off by one hour in php?

I am adding the current date and time to my database using the following code: $current_date_time = time(); echo date('n/j/y g:ia',$current_date_time); It shows up as 11/29/09 12:38am when it should be 11/29/09 11:38am The time is ahead by one hour. I am in the Pacific time zone and my hosting provider is in Utah, the Mountain Time...

dynamic iframe height depending on PHP content ?

How can I set my Iframe height to be dynamic to its content. The content is only PHP code, nothing else. I use the php to query database, and then show some ads. The more ads, the higher the iframe should be. I thought height='100%' should do it, but no... I have read other Q but their solutions doesn't work for me. Suggestions ? T...

Streaming MP3 with open source PHP

What are the best PHP solutions for a blip.fm-like fixed audio player? ...

Why wont this resize of iframe height work?

I have a form on my main page (main.html) with the target set to an iframe on that page. The action of the frame on the main page is a php file. So, the php file displays in the iframe basically. Now, I have this script in the php file to get height of content: var x = document.body.scrollHeight; window.parent.document.getelementbyid("...

Check if_parent and if_child in Wordpress

I need to create a function for WP that will check if the current category is both child of X category and parent to Z category. Ideas? ...

MYSQL, how to get rows with field value of 'x' in this case ?

I am using PHP to query a mysql db. After the query, I am using mysql_fetch_array in a while loop to display all results inside a table. Now, depending on a variable ($adtypes) I want the query-results-array to change... Explanation: ($query_results is the name of the array containing the query results, basically something like SELEC...

php M or F (male or female)

I know there are more elegant ways to set up an html form to take the input of male or female; however, I am learning, and I was just wondering if this is also possible: //Incorporate two checks if (empty($_POST['sex'])==FALSE && sanityCheck($_POST['sex'], 'string', 1)==TRUE) { // if the checks are ok for sex we assign sex...

How do I set a header() and echo an image using CodeIgniter?

Hi, I've written a method to set a header() to the appropriate file type of an upload stored in a database and then I would like to echo() the file. The method is as follows inside a controller: function view_upload( $id = 0 ) { $id = $this->db->escape( $id ); $query = $this->db->query( "SELECT file_type FROM media WHERE id ...

Download web page with images and stylesheets and (optionally) E-mailing it

I need to make snapshots of web pages programmatically using PHP and get them into a HTML E-Mail. I tried wget --page-requisites. It downloads everything all right, but it doesn't change the HTML page's source code to point to the downloaded files rather than the on-line originals. Also, that HTML is of course a long way from being dis...

Unit testing in CakePHP?

I'm wondering, how do you guys unit-test in CakePHP? How do you incorporate tests in projects? What parts of a project do you test? How do you decide which parts gets to be unit-tested? Do you guys still get to finish the job before the deadline? I'd really appreciate your answers. Thanks in advance! ...

Reference and Overwriting

I have: class A{ public $name = 'A'; public $B; public function B_into_A($b) { $this->B = $b; } } class B{ public $name = 'B'; public $A; public function new_A_into_B($a) { $this->A = new $a; } } $a = new A; $b = new B; $a->B_into_A($b); $b->new_A_into_B('A'); Is this a goo...

PHP preg_match_all help

Hey guys. I am trying to match the FDSize: in the following: Gid: 48 48 48 48 FDSize: 64 Groups: 48 425 VmPeak: 289928 kB It comes from /proc/status is not fixied length, and neither is the lines above or below. Can any one help? Thanks ...

Is there a MySQL equivalent of php's Preg_Replace?

When I search the db for a certain value, say a singular noun like "party", I want to be able to get the value "party" from the db, even though it's actually "parties". For that I thought about replacing the -ies suffix for -y, which didn't have any conspicuous exceptions (maybe "lies"). Is there a MySQL equivalent to the PHP Preg_Repla...

Drupal CCK filefield variable access

Hey Everyone, Just wondering can anyone tell me how to access the file field variable in drupal? I can access the rest of the node's variabels with the following php: $node->field_event[0]['value']; But I do not know how to access the content of a file field called field_pdf. I know it is created with something like: $node->field_p...