php

php XML and hash/associate arrays

Using PHP's SimpleXML i would like to get the key and child of an element. The first element if there are more then one. How do i do this? the 2nd line doesnt make sense so how would get the first key/val of the first element? $body = $xml->Body; $xml->Body->children() as $XX=>$ZZ; echo "x $XX $ZZ\n"; foreach($xml->Body->children() as $...

CodeIgniter and PostgreSQL - Retrieving data from Function returning refcursor

I have a PostgreSQL function that selects data and returns it via a refcursor, similar to the following declaration: CREATE OR REPLACE FUNCTION my_function() RETURNS refcursor AS ... How do I retrieve data from this function via a CodeIgniter model? I can't just SELECT directly from the function as it does not return the data dire...

PHP CLI vs PHP WEB

Hiya All, I am currently running a script that i've created in PHP that parses and sorts out 6 different xml files of around 40mb each. I currently run the script through a browser, and a cron job to wget the page. But sometimes with the server load it can clog up apache and and the rest of the server, Would it make sense to convert...

String Check operation in MySQL and Mapping it to a different Value

Hi Friends, I have a MySQL table in which i have a time field in INT(10) format. I am storing UnixTime in it. Some of the records have a Zero value and some have a date in it. I want to build a query which shows "No Date" if the value is 0 else show the stored date if there is any date stored in the record on query execution. The table...

Can I call multiple FFMPEG processes on a multi-core LAMP machine from PHP?

I am using PHP to call an FFMPEG command using exec(). The script that initiates this command is called from another PHP script using proc_close(proc_open('php /phpdirectory/process.php &', array(), $foo)); This works great. The ffmpeg command is called and runs 'in the background' leaving the first script to return to the user and i...

Find out HTTP method in PHP

How can I find out which method (usually GET or POST) is used for the current request? ...

Call a model from a view when using MVC in joomla?

I am developing a custom component in joomla while trying to use MVC. How do I call a model from a view? ...

Create PHP array from MySQL column

mysql_fetch_array will give me an array of a fetched row. What's the best way generate an array from the values of all rows in one column? Edit: Lots of great answers. Thank you everyone who replied! I ended up going with a solution similar to what Gumbo and GSto suggested. I gave the answer points to GSto because he has less points (ju...

Make an if statement shorter

Hay all, I have an if statement. How could I make this as short as possible? if ( $a < 0 ){ if( $a > -2 ){ echo "standard"; }elseif( $a <= -2 && $a > -4 ){ echo "thin"; }elseif( $a <= -4 ){ echo "super thin"; } }else{ if( $a < 2 ){ echo "standard"; } if( $a > 2.01 && $a <= 4){ echo "thin"; } ...

Regular Expression vs XML Functions in PHP

Hiya, I currently do alot of data parsing, and have toyed with PHP functions for XML such as simple XML and a few others here and there. But there always seems to be some sort of issue with dealing with them, mainly due to the way the data is presented. The most reliable way i have found is to always just simply use preg_match_all a...

How can I theme the template for edit or add a node for a specific content type?

I want to theme the template for edit or add a node for a specific content type. For example, to theme all the content type forms I use the file page-node-{add|edit}.tpl.php (depending what I need to do add or edit). But I didn't found the template name for a custom node type, for example Products. I need to theme only for Products, bu...

Does anyone know of any good tutorials for using the APIs from Amazon WeB Services, namely CloudWatch?

Hi, I have been wrestling with Amazon's CloudWatch API with limited success. Does anyone know of any good resources (other than amazon's api docs) for using the APIs. I have tried to run them using the PHP library for CloudWatch but get nothing but error codes. I am configuring the GetMetricStatisticsSample.php file as follows: $request...

magento prices inclusive of tax

Hi there, I have set up my products so that their price is inclusive of Tax. However when I get to the Checkout page, the tax is being added to the Product Price. Where really it should only be there as a summary. Anyone know how to fix this? Regards, Fiona ...

Retrieve partial web page

Is there any way of limiting the amount of data CURL will fetch? I'm screen scraping data off a page that is 50kb, however the data I require is in the top 1/4 of the page so I really only need to retrieve the first 10kb of the page. I'm asking because there is a lot of data I need to monitor which results in me transferring close to...

Need to pass appropriate values to ldap_search

I want to search our Active Directory for the username: johndoe I am unsure of what o and c is in this. $sr=ldap_search($ds, "o=Staff, c=LDAP_DOMAIN_NAME", "uid=johndoe"); Is uid the appropriate parameter to search for a username within Active Directory? If not, what is the appropriate one. I want to search thru the staff group, I t...

Add a decimal point 2 chars from the right under PHP

I have a big array containing lots of elements containing numerical data. Example: 3200 34300 1499 12899 I want to convert these into: 32.00 343.00 14.99 128.99 How can I achieve this elegantly under PHP using no regex? Thanks in advance. ...

Is there a short-circuit OR in PHP that returns the left-most value?

In some languages, you can do $a = $b OR $c OR die("no value"); That is, the OR will short-circuit, only evaluating values from left to right until it finds a true value. But in addition, it returns the actual value that was evaluated, as opposed to just true. In the above example, in PHP, $a will be the value 1 if either $a or $b are...

Where to store uploaded files in PHP & MySQL?

I'm solving problem of storing files in my web app. I've already done some applications where files were stored in filesystem (simple upload of a file via PHP) and I wasn't sure how to solve the security issues correctly (I have the webapp on a shared webhosting). Is there any "manual" or book which target these issues in detail? Rece...

Google Map - Take coordinates

I have google map on my site(php,apache,mysql). here is code: <script type="text/javascript"> function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); var point = new GLatLng(<? $default_ll ?>,<? $default_spn ?>); map.setCenter(point, 15); ...

Php GET notice problem

Calling "index.php?pConta=1&pDataInicial=01-01-2000&pDataFinal=31-12-2000" I get this notices: [08-Oct-2009 17:30:35] PHP Notice: Undefined index: pConta in index.php on line 1 [08-Oct-2009 17:30:35] PHP Notice: Undefined index: pDataInicial in index.php on line 2 [08-Oct-2009 17:30:35] PHP Notice: Undefined index: pDataFinal in ind...