php

Make an option selected based on $_GET. Is this even possible?

Hi, I have a quick question. Is it possible to do something like this? The options are generated dynamically based on foreach loop. I want the loop to stop where the $_GET['t'] equals the $k and make it selected. <option value="http://domain.com/&lt;?php print $k; ?>/" <?php if ($k == $_GET['t']) print 'selected'; ?>><?php print $v; ...

How to unzip files using PHP if safe mode is on and you can't install extensions?

Are there any PHP-scripts out there that can unzip regular zip-files? The requirements we have is that we must run with safe_mode on and we're not allowed to install any extensions to enable this functionality. Thus, any functionality must be regular php scripts. Any thoughts? EDIT: Unfortunately, neither of the posted solution works...

PHP error in .xml file?

OK firstly, I added this line to my .htaccess file so the php engine parses php code in .xml file: AddType application/x-httpd-php .php .php3 .phtml .html .xml After that when I view an .xml file I get this PHP error: Parse error: parse error, unexpected T_STRING in /var/www/vhosts/mydomain.com/httpdocs/test.xml on line 1 But line 1...

Fastest way to format SQL results in PHP

What's the fastest (best performing) way in PHP to transform a (My)SQL result like: array( array('user_name' => 'john', 'tag_id' => 1, 'tag_name' => 'foo'), array('user_name' => 'john', 'tag_id' => 2, 'tag_name' => 'bar'), array('user_name' => 'rick', 'tag_id' => 3, 'tag_name' => 'foobar'), array('user_name' => 'rick', 'tag_id' => 2...

redirect user, then log his visit using php and mysql

I have a PHP redirect page to track clicks on links. Basically it does: - get url from $_GET - connect to database - create row for url, or update with 1 hit if it exists - redirect browser to url using Location: header I was wondering if it's possible to send the redirect to the client first, so it can get on with it's job, and t...

Can I use a dll written in C with PHP?

We are interfacing with a piece of hardware developed here, and allowing access via the web. The firmware for this device is written in C, and part of that firmware is about 5000 lines of code that parses huge binary files for config data, compiled to a .dll. Is there any way under heaven that I can access a .dll, written in C, from PH...

Regexp: how to remove *everythings* except another regexp?

Hi guys, i have some regexp (like ^\w+[\w-.]\@\w+((-\w+)|(\w)).[a-z]{2,3}$, to match correct emails), but i cant figure out how to remove everythings that dont match the regexp in my string. Keeping the email example, i need a way to, given a sting like $myString = "This is some text, the email is here [email protected], and other th...

How to prevent, counter or compensate for, an empty/NULL field (MySQL) returning an empty set...

I'm learning PHP and MySQL to get a hang of server-side scripting and for personal interest/development. The first 'program,' beyond 'hello world' seems to be writing ones' own blog. This is a little beyond me yet and so thought I'd start with a contacts-database type. So far so good, but (and there's always the but!) I'm trying to form...

How to remove 0's from a string

I'm looking at the function trim but that unfortunatily does not remove "0"s how do I add that to it? Should I use str_replace? EDIT: The string I wanted to modify was a message number which looks like this: 00023460 The function ltrim(00023460, "0") does just what I need :) obviously I would not want to use the regular trim because it...

javascript and php on the fly calendar

I have the code for a javascript calendar and it works perfectly as it creates it when the page loads. However I was wondering if it's possible to add events to it. I found a plugin (jQuery) that enables the user to hover over a td with class "event" and an event will be displayed. So since this calendar will not be used by me but by som...

performance of array cloning

We all know that $a1 = array('foo'); $a2 = $a1; $a2[0] = 'bar'; // now $a1[0] is foo, and $a2[0] is bar. The array is copied However, what I remember reading, but cannot confirm by Googling, is that the array is, internally, not copied until it is modified. $a1 = array('foo'); $a2 = $a1; // <-- this should make a copy // but $a1 and ...

Creating a timed validation with PHP and MySQL

How would I go about creating a system in which a user must click a link to validate something. Let us say that on my website, each user has their own folders that are not shared. I want their to be an option for each user on their account page in which they can create a trust with another user to access each others folders. Perhaps by ...

anyone tried new php beta release with anonymous functions?

Hi, has anybody tried out the new 5.3.0 RC1 php release and played a bit with anonymous functions? I would like to know if you can use it like python for functional programming. E.g., can you do something like: def sinus(x): if x<=0.1: return x else: return (lambda x: 3*x-4*x*x*x)(sinus(x/3)) print sinus(172.0) Or bet...

Automated E-mail with PHP and MySQL?

How can I send an automated e-mail to a users entered e-mail address? I have Xampp, which is a local web server equipped with Apache, and Mercury for mail. Ideas? ...

Remove Orphaned Items In A Hierarchy

I have a list of items in MySQL, connected through a column "parent_id". Let's assume the columns are: id, name, parent_id If one of my users deletes an item high in the hierarchy, I need to delete all of its children. So, two part question: 1) Is there an effective and efficient MySQL call that will return ID's for all items where ...

put in p tags using php?

Hi, I know this is an elementary question for you php people out there: I put p tags around in some php by doing this: echo "<p>"; echo $VM_LANG->_('PHPSHOP_COUPON_ENTER_HERE') . '<br />'; echo "</p>"; It is a silly way to do it. So how can I put the p tags within the one 'echo'? ...

Please teach it about mysql_pconnect.

I read specifications of mysql_pconnect of the function of PHP.. "mysql_pconnect is that connection with the SQL server is not closed even if the practice of the script is finished". There is it unless connection is closed, but will it be that connection stays until a timing of the reboot of mysql? ...

Can a PHP file name (or a dir in its full path) have UTF-8 characters?

I would like to access a PHP file whose name has UTF-8 characters in it. The file does not have a BOM in it. It just contains an echo statement that displays a few unicode characters. Accessing the PHP page from the browser (FireFox 3.0.8, IE7) results in HTTP error 500. There are two entries in the Apache log (file is /க.php; the let...

imagecreatefromjpeg() error - Why is my image manipulation script failing?

Hey everyone, I am currently using an image manipulation script to do some work on uploaded images and I'm running into a problem in my dev environment. This same code works on my production server. The error is: PHP Warning: imagecreatefromjpeg(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/to...

Cross platform PHP caveats?

I've been given an existing PHP application that was originally deployed on a LAMP host. Because most of our team are .Net developers, our boss wants it deployed in a windows environment. Is it madness to expect this to just work? Here's some additional info of the LAMP host: Linux 2.4.32 PHP 5.2.6 No non-default modules ...