php

Any way to access array directly after method call?

Is there any way to do this in one line? $arr = $foo->getBarArray(); return $arr[0]; This throws an error: return $foo->getBarArray()[0]; ...

Renaming PHP URLs with HTACCESS

I am building a web app that puts out a link like the following: http://www.sample.com/?a=bj7phm I would like for it to look something like this: http://www.sample.com/BJ7PHM Is this possible within the HTACCESS? -B ...

implode invalid arguments

function delete($rowid) { $rowids = implode(", ",$rowid); $sql = "DELETE FROM pms WHERE id IN (".$rowids.")"; print $sql; } if (isset($_POST['submit'])) { delete($rowid); } ?> <form method="post" action="test.php"> <input type="checkbox" name="rowid[]" value="1771367" /><br > <input type="checkbox" name="rowid[]" value="...

Secure random number generation in PHP

Use case: the "I forgot my password" button. We can't find the user's original password because it's stored in hashed form, so the only thing to do is generate a new random password and e-mail it to him. This requires cryptographically unpredictable random numbers, for which mt_rand is not good enough, and in general we can't assume a ho...

Question about memcached

Some questions about memcached I would like to implement memcache on my social network site, being a social network most data changes very frequently, For example if I were to store a users 10,000 friends into cache, anytime he adds a friend cache would need to update, easy enough but also it would need to update anytime someone else ad...

Is it possible to make an object return false by default?

Hey Stackfolk, I tried to ask this before, and messed up the question, so I'll try again. Is it possible to make an object return false by default when put in an if statement? What I want: $dog = new DogObject(); if($dog) { return "This is bad;" } else { return "Excellent! $dog was false!" } Is there a way this is possible? ...

A better logging design or some SQL magic?

I'm knee deep in modifying some old logging code that i didn't write and wondering what you think of it. This is an event logger written in PHP with MySQL, that logs message like: Sarah added a user, slick101 Mike deleted a user, slick101 Bob edited a service, Payment Broken up like so: Sarah [user_id] added a user [message], slick10...

How do you document your PHP functions and classes inline?

I know there are many different standards for PHP code inline documentation. Here's what I mean by inline documentation, and please correct me if there is a better term: /** * This is the description for the class below. * * @package my-package * @subpackage my-subpackage * @author my-name * @version my-version * ... */ class ...

What is the meaning of \x00 , \x04 in PHP

i have some codes having the \x00 and \x04 hex codes, what does it means? $str= implode("\x00", $var['message']); //line 1 $id= $var['message'] . "\x04" . $id; //line 2 what will happen in the line1 and line2 I want to write these into a external file as binary format. where do i get all information like this. ...

Login / Logout on an iPhone app

I would like to know about managing user's login and logout on IPhone native apps. For example, every time my app is running, the user must be logged in. The information the app serves and the list of users it's on a website running php+mysql. What's the "standard" procedure for this? Is there any library for handling user's login on a r...

How to build recursive function to list all combinations of a multi-level array?

I have an array that can contain any number of elements. Each element contains an ID and an array called "options" (also with any number of elements). Here is the structure: $arr = array( array('id' => 10, 'options' => array(3, 5)), array('id' => 15, 'options' => array(2, 4, 8, 9)), array('id' => 2...

Is it possible to use the Drupal api to get a list of users?

I would like to get a list of all the users who have been assigned a certain role. I could write my own SQL but I would like to use the api as much as possible. ...

Are include()s faster or database queries?

A client is insisting that we store some vital and complex configuration data as php arrays while I want it to be stored in the database. He brought up the issue of efficiency/optimization, saying that file i/o will be much faster than database queries. I'm pretty sure I heard somewhere that file includes are actually slow in PHP. Any s...

Zend_OpenId_Consumer login function hangs - even in the sample code

I've been trying to get a simple OpenId log-in working using first php-openId (Jain) and then the ZendFramework, and in both cases I run up against a similar problem. I'm using the example Zend code from step 38.2.2 of http://framework.zend.com/manual/en/zend.openid.consumer.html. I see the log-in page fine, but when I enter my openId, ...

Regular Expression To Extract Lines Not Cotaining HTML Block Tags

Hi. I'm looking for a regular expression to extract all adjacent lines not containing HTML block tags, but they can contain HTML inline tags. For example, if I have the following text ... bla bla bla bla bla <code>bla bla</code> bla bla bla bla bla <img src="" alt="" /> bla bla bla bla <div> bla bla bla bla bla bla ... I would like t...

php: stripping unwanted characters

I'm using HTML entities on a string of rich html text, but some characters like  are still coming through... how can I either force english-only while still preserving html formatting or force them to HTML? ...

array structure of database results

This might be quite a trivial question, but which of these methods is best practice for structuring an array for return db results? say a list of blog posts... Sorting and grouping posts? or sorting and grouping elements? Array ( [title] => Array ( [0] => Untitled [1] => Untitled ) [id] ...

How do I add checkid_immediate support to a JanRain phpopenid example server?

I'm using an OpenID server based on the JanRain phpopenid library. It's nothing special, simply patched to work with the Yubico onetime password generator. It authorizes fine, but fails the "Successful checkid_immediate" tests at the JanRain diagnosis tool. It says a setup required for checkid_immediate, but I'm not sure what that means....

Connect multiple tables in different databases? MySql.

Hey, I am looking for a good way to connect to at least 2 databases in mysql using php and gathering information within each of those databases from tables. The tables will have related information. eg. I have site names in one database('siteinfo') in a table called 'sites'. I also have the site descriptions in another database('sitede...

Web service: PHP or Ruby on Rails or Python?

I am a .Net / SQL Server developer via my daytime job, and on the side I do some objective C development for the iPhone. I would like to develop a web service and since dreamhost supports mySql, python, ruby on rails and PHP5, I would like to create it using one of those languages. If you had no experience in either python, Ruby on Rai...