php

Find and Store (Regex, PHP)

I'm grabbing a list of tags used on a post with the $posttags array. In this there's a special tag that I want to store separately: profile-somename. How do I: Find this special profile-somename tag from the list (The value after profile- is dynamic, keeps changing, somename is just an example) Strip profile- from it and Store in a ...

How to add a value to an existing value in php...

Consider my variable $result to be 01212.... Now if i add 1 to my variable i get the answer 1213,but i want it to be 01213.... My php code is echo sprintf('%02u', ($result+1)); Edit: Answers to this question works.. But what happens if my variable is $result to be 0121212 in future... ...

what is an effective way to protect mp3 files from download?

Possible Duplicate: Is it possible to protect from downloading a video from a site. i'm looking for a way to allow mp3 files to be streamed using a flash player on a php web page, but to hide and protect these files from download. embedding the file into the swf is unacceptable for this project, since there will be many mp3 f...

PHP Optimize Function in Loop

I am micro-optimizing this function and have a bit of a problem where inside a loop I am checking if a value outside of the loop is 0, if so call function and similarly in the function it calls. How would I refactor it so there is no conditional logic (which is slow) inside these loops. foreach($this->layer[$l]->objs as $obj) { //H...

Standalone php jabber client in browser without javascript

Hi all, Is there any way to maintain stream from php to the jabber server without javascript to keep the client side live? Some low end mobile do not support javascript, so to maintain permanent connection to server is key question? any hacks? ...

PHP dictionary class? or alternative?

Hi. Basically, what I'm looking for is some kind of class or method to implement a dictionary in PHP. For example, if I was building a word unscrambler - lets say I used the letters 'a,e,l,p,p'. The number of possibilities for arrangement is huge - how do I only display those which are actual words (apple, pale etc )? Thanks! ...

Building URL in CodeIgniter

I'm basically trying to grab everything after the 4th segment in the URL, however there is no fixed number of segments. Here is my attempt but for some reason $url is always 0 rather than the string I am looking for. Any suggestions? $url = ''; for ($counter = 4; $counter <= $this->uri->total_segments(); $counter++) { $url += $this-...

display date and time something like blog

I am having the blog, Regularly i post some fun thing, my user response for that, i maintain the timestamps for response time, How to display the something like this 2010-02-09 1hour before, if reply is just 1hour old 2010-02-09 20hour before ,if reply is just 20hour old 2010-02-08 yesterday ,if reply is just 1day old 2010-02-...

Turn off option to open xls file in internet explorer from the site?

Hi, BACKGROUND: I have built a web application for a client which allows them to save excel files to the server. When I first built the application I stored these files in an uploads folder and linked to them directly from pages within the application (eg File). On reflection this wasn't very secure so I changed the uploader file to...

How do I set the "From" address in a PHP contact form?

Hi I have a problem with the PHP contact form I have created. When I enter information into the form and click submit the information is sent to an email address but there is no senders address attached to the email. How do I create a seneders address so that when the user clicks sumbit it will send the email with thier email address...

Selecting distinct months and years and then breakdown of values for

I'm using Open Flash Chart to create statistics and one of the things i need to be able to do is generate a Stacked Bar Chart. Logically i need to be able to Group all the distinct Month/Year combinations, Dec 2009, Jan 2010, Feb 2010 etc. and then from that group all the various rows, i.e. the different types of enquiry a visitor made ...

How to implement nested namespace in PHP?

use level1\level2\level3; Can someone explain with a simple demo ? ...

How to handle user input with a mixture of HTML and punctuation?

I have a form field that includes a mixture of HTML and text. I want users to be able to use basic HTML and punctuation. Currently I am using mysql_real_escape_string and preg_replace to sanitise the data and insert it into the database. My understanding is that preg_replace is the best way to strip any characters that are not in a whit...

Best way to do caching on a reddit-like website

We have a PHP website like reddit, users can vote for the stories. We tried to use APC, memcached etc. for the website but we gave up. The problem is we want to use a caching mechanism, but users can vote anytime on site and the cached data may be old and confusing for the other visitors. Let me explain with an example, We have an arra...

php get 1st value of an array (associative or not)

This might sounds like a silly question. How do I get the 1st value of an array without knowing in advance if the array is associative or not? In order to get the 1st element of an array I thought to do this: function Get1stArrayValue($arr) { return current($arr); } is it ok? Could it create issues if array internal pointer was moved...

Select Query with MAX

Hey Guys, i've got a big Problem and i was trying the whole day and did not find any Solution. Hope you can help me? I have two tables: The first one named "orders": orders_id | orders_date | ..... 1 xxxxxxxxxx 2 xxxxxxxxxx 3 xxxxxxxxxx The second is "orders_history": orders_id | order_status_id | dat...

Question about including html page in PHP

Hi, If I include an HTML page on a PHP page (say, index.php) with the following: <?php include ("../../forms/login/form.html"); ?> Then will form.php show up correctly in index.php? When I say correctly, I mean with all of its images and CSS. The reason I am asking is because that's not the case with me. I tried it out, and it will...

Lots of DESCRIBE queries in Zend Framework

I just set up FirePHP in Zend and I'm noticing a huge number of DESCRIBE queries. Some pages have 50 or more identical queries all on the same table. e.g. 0.00198 connect NULL 0.00449 DESCRIBE `nodes` NULL 0.00041 SELECT `nodes`.* FROM `nodes` WHERE (((`nodes`.`id` = 111))) NULL 0.0037 DESCRIBE `nodes` NULL 0.00155 SE...

PHP shell_exec() and sudo: must be setuid root

I have a shell_exec() command that accesses a directory above my document root so I need to use sudo "as root" to make it happen. (I understand the security issues and am putitng in measures to address it). The issue is when I run the shell_exec() I get a "sudo: must be setuid root" error in my apache error_log file. I thought the solu...

Making a url with timestamp, whitespace between date and time breaks url

Hi, I'm working on the Head First PHP and MySql book, and I have this problem with a date/timestamp. I'm going to make an URL with a date as a GET parameter. But when the date is returned from the database (type of timestamp), there is a white space betwen the date and the time, so the URL breaks. How can I format the date to get incl...