Monday, December 22, 2008

Making a Link Select a Select Box in Javascript

I needed to have a link select an option within a selectbox.  What I wanted to do was have a bunch of links out there and if a user clicks one, move down the page and have a value in my selectbox already selected according to that link.

I found a solution online that worked great.  It uses javascript, but works wonderfully.

Since blogger doesn't let me paste code easily, I'll just direct you to the link.  If it ends up being dead in the future, please leave a comment and I'll post the code.



Tuesday, December 16, 2008

Server Root Path with PHP

Here is a simple way to get the server root path with PHP:

$_SERVER['DOCUMENT_ROOT']

Say you want to check if a file exists, you could do this:

file_exists($_SERVER['DOCUMENT_ROOT']."/yourfolder/yourfile.extension")

Putting this in an IF statement will see if the file exists.  If it does, file_exists will return true, else it will return false.

Friday, December 5, 2008

Trim Whitespace in PHP

Trim is a nice built-in function for PHP.  My default it will trim off the whitespace from the beginning and end of a string.

Description

string trim ( string $str [, string $charlist ] )

This function returns a string with whitespace stripped from the beginning and end of str . Without the second parameter, trim() will strip these characters:

  • " " (ASCII 32 (0x20)), an ordinary space.
  • "\t" (ASCII 9 (0x09)), a tab.
  • "\n" (ASCII 10 (0x0A)), a new line (line feed).
  • "\r" (ASCII 13 (0x0D)), a carriage return.
  • "\0" (ASCII 0 (0x00)), the NUL-byte.
  • "\x0B" (ASCII 11 (0x0B)), a vertical tab.      

Returning Content to PHP Variable with cURL

I have a few examples of using cURL here in PHP but this parameter allows you to store the content of the selected source to a PHP variable.

Say, for example, you are loading up a page with cURL and want that information store in a PHP variable to use throughout your site.  You can do this by adding the following code to your cURL request:

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); // return the page content

So here is a full block of code:

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'URL_TO_THE_PAGE');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$savedvalue = curl_exec($curl_handle);
curl_close($curl_handle);

In this case, $savedvalue will hold all the information returned by that page request.

cURL is very powerful and worth learning about.  Here is a good resource: PHP login/download file - CURL libraries.

Thursday, December 4, 2008

PHP Header Redirect

Most people may already know this but for some reason I always forget the syntax (I know... its simple...).  So here is how you can redirect to a page with PHP.

Remember: You have to redirect BEFORE loading any HTML tags or header information.  This should always be tested before ANY echo/print tags or any output.

header('Location: http://www.example.com/');
exit;

Don't forget the exit, this prevents the rest of the page from loading and possibly stopping your redirect.

Tuesday, December 2, 2008

Flash Multiply Error

Flash PNG or any image Multiply Filter error.

I am having trouble with the "multiply filter" in Flash. Evidently, I am not the only one.

Someday, I hope to find an answer.


Here's a guy who posted the SAME issue:
http://www.bitsofstring.org/extra/flash/flashblendingtest.html