Tuesday, December 29, 2009

.htaccess ErrorDocument does not Catch 404 Error from a Non-Browser Call to the Site.

I came across this problem recently when trying to click on hyperlinks in a WORD document. The link used the following code in a .htaccess file.

ErrorDocument 404 /error_file.php

It worked when accessing the link through a browser, but WORD makes a call to the site first to determine if the page exists. For some reason, the file would not redirect, and WORD would say that it could not access the site. The same thing would happen when trying to access the page via PHP cURL or a W3C validator.

Thanks to the following page, I indirectly got the solution.
The page is actually discussing .htaccess files nested in subfolders, but the following code, which is mentioned in the posts, works better for redirecting from WORD.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /error_file.php [L]

Wednesday, November 11, 2009

How to have clickable links in Yahoo Answers

I came across this problem when first starting giving answering questions on Yahoo Answers. You'd paste a link into an answer and when you view the submited answer, the link is not active (not clickable). It's just part of the text of the answer.

Well, after not getting many answers about from Yahoo Answers, I stumbled on the solution myself after answering more.

You have to get to Level 2 of Yahoo Answers in order for your links to be clickable.

Sunday, November 8, 2009

Easy Object Call HTML DOM / JavaScript

Here's a handy little function that I use a lot. Instead of having to call document.getElementById('example_tag') which is long and half the time I mis-capitalize the "getElementById", this function saves time and errors with getEle('example_tag') The plus is that it also bypasses a potential error if the element is not there.
function getEle(str){
return document.getElementById(str);
return false;

Friday, November 6, 2009

JavaScript HTML to XHTML Converter for Yahoo's YUI 2 Rich Text Editor

The other day after installing Yahoo's Rich Text Editor, I noticed that the output of the editor was badly formed HTML that wouldn't validate on my XHTML site. So, since I'm a bit anal, I wondered if there was a way to convert the output. After only finding a few convoluted and licenced solutions, I figured it wouldn't be too hard to do it myself. So here it is in JavaScript.

function convertToXHTML(html){

var raw1 = html.split("<"); var xhtml = ""; var tags = ""; //Make Tags Lower Case and make sure that the tags are properly closed for(var i in raw1){ if(raw1[i].indexOf(">") != -1){
var raw2 = raw1[i].split(">");
var tagName = (raw2[0].indexOf(" ") > -1) ? raw2[0].split(" ")[0] : raw2[0];
tagName = tagName.replace(/\//g, "");
var endSlash = (html.indexOf("/" + tagName) == -1 ) ? " /" : "";
raw2[1] = (raw2[1]) ? raw2[1] : "";

if(raw2[0] != "" && raw2[0]){
var begin = "<" + raw2[0].replace(eval("/" + tagName + "/"), tagName.toLowerCase()); xhtml += begin + endSlash + ">" + raw2[1];
xhtml += raw1[i];

//Make sure that the attributes listed below use quotes
xhtml = xhtml.replace(/align=center/gi, 'align="center"');
xhtml = xhtml.replace(/align=left/gi, 'align="left"');
xhtml = xhtml.replace(/align=right/gi, 'align="right"');

//Make sure the attributes are separated by a space
var arr = xhtml.match(/"[a-z]+="/gi);
for(var i in arr){
xhtml = xhtml.replace(eval("/" + arr[i] + "/gi"), '" ' + arr[i].slice(1));
return xhtml;


Unfortunately, this isn't a 100% fix. The Yahoo Editor sometimes nests the tags in an invalid way, and I have yet to correct for that. I also haven't tested this too much yet; so, there could be quite a few other things that this isn't designed to fix.

This is specifically to convert the output of Yahoo's text tool. This function fixes glitches that only this tool creates, and does not account for errors that you or another program might export.

Wednesday, November 4, 2009

Problem Pasting from Clipboard on Blogger

This has been bugging me since I started this blog. If you have Internet Explorer 8 and cannot copy and then paste text into your Blogger Post Textbox, just turn-on "Compatibility Mode".

Go to Tools / Compatibility Mode

While you're at it, you may as well set Blogger to be in compatibility mode into the future; so, got to Tools / Comaptibility Settings. This brings up a Menu Box. Enter "Blogger.com" into the text field at the top and click "Add" then click "Ok". This makes it so Blogger is in Compatibility Mode everytime you go here.

I haven't fully tested this to see if it makes anything else not work, but at least you can copy and paste. I found this here: http://www.google.com/support/forum/p/blogger/thread?tid=418da73cad5aa018&hl=en (I copied and pasted this while in compatibility mode).

Monday, November 2, 2009

URL Encode Calculation / Function for FileMaker Pro

This function is for when you send field data to a website with the "Open URL" Script Step, or if you're storing url encoded links.

Substitute (
; ["¶" ; "%0D"]
; ["%" ; "%25"]
;[ "#" ; "%23"]
;[ "`" ; "%91"]
;[ "~" ; "%7E"]
;[ "!" ; "%21"]
;[ "@" ; "%40"]
;[ "$" ; "%24"]
;[ "^" ; "%5E"]
;[ "*" ; "%2A"]
;[ "(" ; "%28"]
;[ ")" ; "%29"]
;[ "-" ; "%2D"]
;[ "_" ; "%5F"]
;[ "=" ; "%3D"]
;[ "+" ; "%2B"]
;[ "" ; "%3A"]
;["\\" ; "%5C"]
;[ "]" ; "%5D"]
;[ "[" ; "%5B"]
;["{" ; "%7B"]
;[ "}" ; "%7D"]
;[ ";" ; "%3B"]
;[ ":" ; "%3A"]
;[ "'" ; "%27"]
;[ "\"" ; "%22"]
;[ "<" ; "%3C"]
;[ ">" ; "%3E"]
;[ "," ; "%2C"]
;[ "." ; "%2E"]
;[ "/" ; "%2F"]
;[ "?" ; "%3F"]
;[ "&" ; "%26"])

Now, I created this function about a year or two ago on my own, but out of curiosity, I just did a google search for "urlencode filemaker" and found an incredibly similar function on Brian Cummings FileMaker Pro Custom Functions page. So, out of fairness, I'll give him credit for his or his team's work,
but I swear I couldn't find his page when I made the calculation. However, my function does have a few more encoded characters.

Anyway, hopefully this will help anyone else out there looking for such a function.

Friday, October 30, 2009

IIS 7 PHP FTP permissions error with ftp_nlist() and ftp_rawlist()

How `bout this! Two posts on my first day on the blog.

This one I encountered soon after finally getting my SSL up and running. In IIS 7, PHP my have some permission errors that will allow an FTP connection to go through, but as soon as you call ftp_nlist or ftp_rawlist, the script keeps running and causes a 500 Server Error.

Well, the simple solution is to force passive mode. Call this after connecting to the FTP.

ftp_pasv($conn_id, true);

Now, this might not be the best solution for you, especially if you're connecting to a typically stupid Windows Server 2008 that does not easily allow passive FTP, but it worked for me; so, if this doesn't work for you, just go punch the insensitive loudmouth sitting next to you .