php

finding common prefix of array of strings

I have an array like this $sports = array( 'Softball - Counties', 'Softball - Eastern', 'Softball - North Harbour', 'Softball - South', 'Softball - Western' ); and i would like to find the longest common part of the string so in this instance, it would be 'Softball - '; I am thinking that I would follow the this process $i = 1; // ...

How to document a Class and shows its constructor params when instantiating, using Netbeans autocomplete?

I'm documenting the company framework for use with our default IDE (Netbeans). It's normal that we send as params a new Object, like here: $this->addControl(new TextControl('name', 'value')); I could document the __construct() params at the normal place, but they aren't showed when you do a new <ctrl+space>. So I tried to move this d...

php global trim $_post

Could you trim all $_POST vars? because i have a very long list right now for trim each var. looks very unprofessional. i thought trim($_POST); would maybe work but it didnt :] ...

file_get_contents behind a proxy?

At work we have to use a proxy to basically access port 80 for example, we have our own custom logins for each user. My temporary workaround is using curl to basically login as myself through a proxy and access the external data I need. Is there some sort of advanced php setting I can set so that internally whenever it tries to invoke ...

PHP Class for logins

I am looking for a good class for logins. I don't need a login or registration form. Just the behind the scenes stuff mostly. Looking for recommendations. ...

How do i set the selected item in a drop down box (PHP MySQL Databound)

Hi Is there any way to set the selected item in a drop down box using the following 'type' code? <select selected="<?php print($row[month]); ?>"><option value="Janurary">January</option><option value="February">February</option><option value="March">March</option><option value="April">April</option></select> The database holds a month...

PHP Java combination for multithreaded processing - good or bad ?

Hello, i need to make multiple calls to different web services using PHP and i was wondering if the php-java combination would be more appropriate in dealing with this issue. The multiple calls to the services if called sequentially will create a significant amount of delay, so i am looking for ways to overcome that. I have read arti...

Alternating CSS Style with multiple Mysql Results

I've got a site where someone searches for x product in their location and the site spits back a list of results. if(isset($_POST['zip'])){ $qry="SELECT business_id FROM ".TBL_BUSINESS." WHERE zip LIKE '%".$_POST['zip']."%'"; $rs = mysql_query($qry); $rec = array(); while(($row = mysql_fetch_array($rs)) !== FALSE ){ $rec[] = $row[0];...

Is there an easy way in PHP to convert from strings like '256M', '180K', '4G' to their integer equivalents?

I need to test the value returned by ini_get('memory_limit') and increase the memory limit if it is below a certain threshold, however this ini_get('memory_limit') call returns string values like '128M' rather than integers. I know I can write a function to parse these strings (taking case and trailing 'B's into account) as I have writt...

Simple(r) ORM for PHP

What is the simplest ORM implementation around for PHP? I'm looking for something really simple and light (in terms of LOC, since speed it's not crucial I don't need caches and what not), preferably a single file or class package that doesn't depends on XML or other configuration files and it's easy to deploy. Reading other similar ques...

php: remove brackets/contents from a string?

If I have a string like this: $str = "blah blah blah (a) (b) blah blah blah"; How can I regex so that the output is: $str = "blah blah blah blah blah blah"; Needs to be able to support any number of bracket pairs inside a string. Thanks for any answers! ...

XSS filtering function in PHP

Hi, Does anyone know of a good function out there for filtering generic input from forms? Zend_Filter_input seems to require prior knowledge of the contents of the input and I'm concerned that using something like HTML Purifier will have a big performance impact. What about something like : http://snipplr.com/view/1848/php--sacar-xss/ ...

Ruby and PHP HMACs not agreeing

I'm trying to create an HMAC in Ruby and then verify it in PHP. Ruby: require 'openssl' message = "A522EBF2-5083-484D-99D9-AA97CE49FC6C,1234567890,/api/comic/aWh62,GET" key = "3D2143BD-6F86-449F-992C-65ADC97B968B" hash = OpenSSL::HMAC.hexdigest('sha256', message, key) p hash PHP: <?php $message = "A522EBF2-5083-484D-99D9-AA...

PHP: Remove unprintable characters without removing white space.

I know this a common question but everything I found seems to remove white space. I'm looking for a regular expression that will strip unprintable characters WITHOUT changing any whitespace. This a function that all user input will be filtered through, which means all the characters you could normally type on a keyboard are valid. Ex: t...

How to bootstrap Zend_Test_PHPUnit_ControllerTestCase with Zend_Application?

I am used to writing unit tests in Zend Framework 1.9 using PHPUnit_Framework_TestCase for my application. Now I am trying to write a unit test based on Zend_Test_PHPUnit_ControllerTestCase by using the bootstrapping by Zend_Application of Zend Framework. But I am unable to get it running. Here is my nonworking example: class FamilyCo...

Is it possible in PHP to escape newlines in strings as in C ?

In C you can continue a string literal in the next line escaping the newline character: char* p = "hello \ new line."; ( My C is a bit rusty and this could be non 100% accurate ) But in php, the backslash is taking literally: $p = "hello \ new line."; I.E. the backslash character forms part of the string. Is there a way to get the C ...

PHP Merge 2 mysql Results

Hi there I execute 2 query's on 2 diffrend servers with the same table structure. How can I merge the 2 Arrays in PHP? Thanks ...

How can I use a regex to replace a character that is inside two other specific characters?

I'm working on implementing a way to allow HTML in a field that I have with PHP. The characters are saved to the database as they are inputted, so when I print them to the screen later on, I want the HTML to be respected (security is not an issue here, so please don't make it one). What I need right now is a way to change any &quot; inst...

How to use a class's method inside a function (PHP) ?

I'm trying to use the new PHP mysqli extension. I've got a function (safe()) that recursively uses mysql_real_escape_string to make strings safe. How do I use my mysqli connection inside this function to call the mysqli::escape_string() function? Example: $db = new mysqli($host,$user,$password,$database_name); function safe ($data) {...

Count Similar Array Keys

I have a POST request coming to one of my pages, here is a small segment: [shipCountry] => United States [status] => Accepted [sku1] => test [product1] => Test Product [quantity1] => 1 [price1] => 0.00 This request can be any size, and each products name and quantity's key would come across as "productN" and "quantityN", where N is an...