PHP Tips
Regular Expression Online Tester Another checker
Increase upload max from 2M default
First, you'll want to see what your default settings are. I created a small file 'phpinfo.php' to show me the settings:
<?php phpinfo(); ?>
Next, I edited the .htaccess in the directory with the upload script to look like this: <verbatim> php_value post_max_size 33554432 php_value upload_max_filesize 33554432 </verbatim>
Finally, I verified the change with the 'phpinfo.php' page.
Show php source code
This works on many linux setups. Any file with a .phps will be shown as it's PHP source, will HTML coloring. The easy way to add this is to create a symlink like this:
ln -s rss.php rss.phps
Displaying XML
Today I set out to create an XML RSS feed in PHP. I quickly found some examples, and without too much trouble I was getting my feed to validate on http://feedvalidator.org. The difficult part for me was getting the xml file to render as XML in Internet Explorer 6.0.
Here's what my page was looking like:
Here's what I want it to look like:
I knew I needed to include the Content-Type in the header:
<?php header('Content-Type: text/xml'); echo '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'."\n"; ?>
This didn't help any. My xml looked the same. My site is hosted on Apache/Linux, so I started trying to figure out how .htaccess works and MIME types. I tried creating my own .htaccess file and putting ~AddType into it. This didn't work either. So I decided to copy the .htaccess file from my tikiwiki app. Following this my xml fixed itself. Unfortunately, this was not caused by the .htacess file. The reason is I tried my query in a new window. When there were errors in my XML, it would get sent as plain text. Internet Explorer was caching this content type, and not changing when I would refresh the page.