php

Echo A Link, Get A Trailing Slash?

I've discovered that any time I do the following: echo '<a href="http://" title="bla">huzzah</a>'; I end up with the following being rendered to the browser: <a href="http:///" title="bla">huzzah</a> This is particularly annoying when I link to a file with an extension, as it breaks the link. Any ideas why this is happening and ho...

PHP: Replace umlauts with closest 7-bit ASCII aequivalent in an UTF-8 string

What I want to do is to remove all accents and umlauts from a string, turning "lärm" into "larm" or "andré" into "andre". What I tried to do was to utf8_decode the string and then use strtr on it, but since my source file is saved as UTF-8 file, I can't enter the ISO-8859-15 characters for all umlauts - the editor inserts the UTF-8 chara...

How do I install MySQL modules within PHP?

I've updated php.ini and moved php_mysql.dll as explained in steps 6 and 8 here. I get this error Fatal error: Call to undefined function mysql_connect() in C:\inetpub... MySQL doesn't show up in my phpinfo; report. I've updated the c:\Windows\php.ini file from ; Directory in which the loadable extensions (modules) reside. exten...

What happens first? .htaccess or php code?

If I use mod_rewrite to control all my 301 redirects, does this happen before my page is served? so if I also have a bunch of redirect rules in a php script that runs on my page, will the .htaccess kick in first? ...

Creating a file progress bar in PHP

Does anyone know of any methods to create a file upload progress bar in PHP? I have often heard that it's impossible. I have one idea, but not sure if it would work: have a normal file upload, but instead submit to an iframe. When this is submitted, store the file information (size and temp location) in the session. At the same time, st...

Which Type of Input is Least Vulnerable to Attack?

Which type of input is least vulnerable to Cross-Site Scripting (XSS) and SQL Injection attacks. PHP, HTML, BBCode, etc. I need to know for a forum I'm helping a friend set up. ...

How can I parse Apache's error log in PHP?

I want to create a script that parses or makes sense of apache's error log to see what the most recent error was. I was wondering if anyone out there has something that does this or has any ideas where to start? ...

How do I loop through a MySQL query via PDO in PHP?

I'm slowly moving all of my LAMP websites from mysql_ functions to PDO functions and I've hit my first brick wall. I don't know how to loop through results with a parameter. I am fine with the following: foreach ($database->query("SELECT * FROM widgets") as $results) { echo $results["widget_name"]; } However if I want to do somet...

What do I need for a compliant email header

I am trying to send an email from a site I am building, but it ends up in the yahoo spam folder. It is the email that sends credentials. What can I do to legitimize it? $header = "From: site <[email protected]>\r\n"; $header .= "To: $name <$email>\r\n"; $header .= "Subject: $subject\r\n"; $header .= "Reply-To: site <[email protected]>" . "\r\...

Is there a php library for email address validation?

I need to validate the email address of my users. Unfortunately, making a validator that comforms to standards is hard Here is an example of a regex expression that tries to comform to standard Are there any PHP library (preferably, open-source) that validates email address? ...

URL segment to action method parameter in Zend Framework

in Kohana/CodeIgniter, I can have url in this form -> http://www.name.tld/controller_name/method_name/parameter_1/parameter_2/parameter_3 ... and read the parameters in my controller as follows class controller_name_controller { public function method_name($param_A, $param_B, $param_C ...) { // ... code } } is th...

php - imap - moving emails on antoher account

I am working on a script that downloads emails and stores them in a db, I usually receive thousands of emails on this account, once downloaded the mails are deleted. Being paranoic, I want to have at least one month backup of my emails, but I cannot clutter my main mailbox address leaving them in there. So i need to move the mails (via...

Elegant way to merge two arrays as key value pairs in PHP?

I've got two arrays of the same size. I'd like to merge the two so the values of one are the key indexes of the new array, and the values of the new array are the values of the other. Right now I'm just looping through the arrays and creating the new array manually, but I have a feeling there is a much more elegant way to go about this...

Reading very large files in PHP

fopen is failing when I try to read in a very moderately sized file in PHP. A 6 meg file makes it choke, though smaller files around 100k are just fine. i've read that it is sometimes necessary to recompile PHP with the -D_FILE_OFFSET_BITS=64 flag in order to read files over 20 gigs or something ridiculous, but shouldn't I have no prob...

How can I save email attachments to the server in PHP?

I've been battling PHP's email reading functions for the better part of two days. I'm writing a script to read emails from a mailbox and save any attachments onto the server. If you've ever done something similar, you might understand my pain: PHP doesn't play well with email! I've connected to the POP3 server and I can iterate the file...

PHP - How do I include a file over 2 directories back?

How do you include a file that is more than 2 directories back. I know you can use ../index.php to include a file that is 2 directories back, but how do you do it for 3 directories back? Does this make sense? I tried .../index.php but it isn't working. I have a file in /game/forum/files/index.php and it uses PHP include to include a fil...

Setting default values (conditional assignment)

In Ruby you can easily set a default value for a variable x ||= "default" The above statement will set the value of x to "default" if x is nil or false Is there a similar shortcut in PHP or do I have to use the longer form: $x = (isset($x))? $x : "default"; Are there any easier ways to handle this in PHP? ...

Slicing a multi-dimensional PHP array across one of its elements.

Say for example you just queried a database and you recieved this 2D array. $results = array( array('id' => 1, 'name' => 'red' , 'spin' => 1), array('id' => 2, 'name' => 'green', 'spin' => -1), array('id' => 3, 'name' => 'blue' , 'spin' => .5) ); I often find myself writing loops like this. foreach($results as $result) ...

Database Design Issues with relationships

I'm working on an upgrade for an existing database that was designed without any of the code to implement the design being considered. Now I've hit a brick wall in terms of implementing the database design in code. I'm certain whether its a problem with the design of the database or if I'm simply not seeing the correct solution on how to...

Smart pagination algorithm

I'm looking for an example algorithm of smart pagination. By smart, what I mean is that I only want to show, for example, 2 adjacent pages to the current page, so instead of ending up with a ridiculously long page list, I truncate it. Here's a quick example to make it clearer... this is what I have now: Pages: 1 2 3 4 [5] 6 7 8 9 10 11...