Alvin’s Blog

Just another tech blog

  • Home
  • About

Converting Numbers to Alphabets in PHP

posted by Alvin in April 9th, 2008 
in Uncategorized  

Here is a small, but useful, function in PHP to convert numbers to alphabetic characters. So, 1 would return an A, a 4 will return a D, a 27 will return an AA, and so on. I find this function useful if you want to create a list of letters for an index or some sort. Anyways, here is the PHP code with an example on how to use it.


<?php

function numtoalpha($number) { // function

  $anum = "";

  while($number >= 1) {

    $number = $number - 1;

    $anum = chr(($number % 26)+65).$anum;

    $number = $number / 26;

  }

  return $anum;

}


// example:

for ($x=0,$z=0;0<=26;$x++) {

  $convert = numtoalpha($z++);

  echo($convert." ");

}

?>

The example above should have printed the complete alphabet in uppercase a space apart.

email this

Add to deli.cio.us

Digg it

Permalink

No Comment

Preloading Images with Valid CSS

posted by Alvin in March 16th, 2008 
in computers, css, web design   Tags: css, images, preload, valid

Here is a small tutorial on how to preload images using valid CSS. Usually, you could use JavaScript to preload images, but many browsers turn JavaScript off due to security concerns. However, CSS can just as easily do the job, although not as straightforward as JavaScript.

Usage
For this tutorial, we’ll use these two images of the fabulous Lamborghini Murciélago:
Lamborghini Murciélago Image 1
Lamborghini Murciélago Image 2

We’ll be setting up a simple image rollover for a link. Our purpose of preloading the image is because some browsers (especially IE) doesn’t download the image that shows up when you hover over a image link. So there is usually a blink when you move your cursor over a rollover because the developer did not specify the browser to preload the image. Although Firefox generally doesn’t have this problem, since a substantial portion of web users use Internet Explorer, its worth to use this method. So, let’s start.

Step 1: First, we’ll create an HTML file which we’ll use for the images. Create a page preload.html.

Step 2: Now, download the two images above (or use two of your own images) and for our purposes name them lamborghini1.jpg and lamborghini2.jpg. Also, let’s just put them in the same directory as our preload.html.

Step 3: Now, let’s fill in preload.html. We’ll put lamborghini1.jpg in the page and link it to Lamborhini’s official website.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lamborghini Murciélago Picture</title>
</head>
<body>
<div>
<a href="http://www.lamborghini.com/" title="Lamborghini Official Site"><img
src="lamborghini1.jpg" alt="Lamborghini Murciélago" width="400" height="300"
border="0" /></a>
</div>
</body>
</html>

Step 4: Now, we’re going to add the rollover effect for the link. First, let’s edit the HTML file. So, change

<img src="lamborghini1.jpg" alt="Lamborghini Murciélago" width="400" height="300" border="0" />

to

<img id=”hover” src=”lamborghini1.jpg” alt=”Lamborghini Murciélago” width=”400″ height=”300″ border=”0″ onmouseover=”hover.src=’lamborghini2.jpg’” onmouseout=”hover.src=’lamborghini1.jpg’” />

The rollover should work (we used Javascript to do this), but now we’re going to use CSS to preload the rollover image so that some browsers won’t “blink” while loading the image.

Step 5: Add the following right before the closing </body> tag.

<div class="preload"><img src="lamborghini2.jpg" alt="Preload image" /></div>

Step 4: Let’s create a CSS file called style.css and add the following lines to the new stylesheet.

@charset "utf-8";
div.preload {
position:absolute;
top:-9999;
left:-9999;
height:1px;
width:1px;
overflow:hidden;
}

Step 5: Now, for our final step, let’s just link the stylesheet to the HTML file. Add the following line to the head of the HTML file.

<link rel="stylesheet" href="style.css" />

There, we’re done! Although it’s a simple process, I just simplified the steps in case anyone needs the explanation.

Example

Here’s an example of what I’ve been explaining above:

Lamborghini Murciélago

“>Preload image

Why does it work?
The idea behind preloading with CSS is pretty simple. Basically, we actually put the images we want to preload into the HTML but with CSS we resize it to 1×1 and move it out of the way (by positioning the absolute div container to -9999, -9999). So, when the user eventually sees the image, the browser would already have it saved in its cache.

email this

Add to deli.cio.us

Digg it

Permalink

7 Comments

Embedding FLV in WordPress

posted by Alvin in February 18th, 2008 
in computers, mods, scripts   Tags: embed, flv, jw flv media player, wordpress, wp-flv

WordPress is probably one of the most widely used blog scripts in the Internet today and with the growing use of flash videos in the Internet (Youtube, Google Video), integrating both of these can cause a problem. Since WordPress filters out some HTML tags, unless you alter the PHP source script, you will have to use a modification. I personally prefer the mod called WP-FLV. Here is a small guide on how to use WP-FLV.

  1. Create a folder named wp-flv in the plugins folder.
    The /plug-ins folder is located in the /wp-content folder, which is in the WordPress root folder.
  2. Download the JW FLV Media Player, off which this modification is based on.
    Go to www.jeroenwijering.com/?item=JW_FLV_Media_Player and download the player (the latest version is the first one under the History header).
  3. Extract and upload the files into a new folder named jwflvplayer.
    First create the folder /jwflvplayer and then upload the files from the archive into this folder. For this guide, after you extract, open the folder called /mediaplayer-x-xx (note that the x’s stand for number depending on the version you downloaded) and drag the files from there; don’t upload the folder itself. Also, you don’t have to upload the /source folder which is in the /mediaplayer-x-xx folder. So, by now /wp-content/plugins/wp-flv/jwflvplayer/ should have a file called mediaplayer.swf.
  4. Download the WP-FLV modification.
    Go to roel.meurders.nl/downloads/wp-flv.php.txt and save the file as wp-flv.php (without the .txt extension).
  5. Upload the WP-FLV modification to your plugins folder.
    Simply upload the wp-flv.php file to /plugins folder. This should the same folder where the /jwflvplayer folder is located.
  6. Activate the WP-FLV on your WordPress blog.
    In the admin control panel for your blog, click on the Plugins tab on the top and you should see the WP-FLV plugin listed there along with the other plugins. Click Activate the get the plugin working.
  7. Point WP-FLV to the location of the JW FLV Player you uploaded.
    Go to the Options tab on the admin CP. Now go to WP-FLV in the submenu (right below the tabs on the top). The first text box should ask you for the full url to flvplayer.swf. In my download it was called mediaplayer.swf, so we’ll point to that. First, type in the root URL for the blog and then add this: “/wp-content/plugins/wp-flv/jwflvplayer/mediaplayer.swf” (without the quotes). For this blog, it would be http://www.alvinjohnson.net/blog/wp-content/plugins/wp-flv/jwflvplayer/mediaplayer.swf. After your done, click Update Options on the bottom.

If you followed these steps correctly, the plugin should be ready to be used. Basically, this mod lets you embed FLV files by using a <flv> tag when creating posts. To use the tag, begin writing a new post and switch to the Code view. Now, there are four attributes for this tag. The “height” attribute alters the height of the video and the “width” attribute alters its width. The “href” attribute is where you type in the URL of the FLV you want to embed. And finally, the “autostart” attribute determines whether the video should start automatically or not.

Here are a few examples:

<flv href="http://www.example.com/video.flv" height="320" width="240" autostart="false" />

<flv href="http://www.example.com/video.flv" autostart="false" />

<flv href="http://www.example.com/video.flv" />

The first example used all the attributes, but the second one omitted the dimensions. When this happens, the mod uses the default dimensions (these can be edited in the WP-FLV sub-tab under the Options tab in the admin CP) As per the third example, you can also use the default autostart value, which can also be edited. You can also use the WP-FLV quicktag in the Visual view to help you out.

Here’s an example of how a finished product might look:

First the code:

<flv href="http://www.alvinjohnson.net/blog/wp-content/uploads/2008/02/riseagainst_prayeroftherefugee.flv" height="280" width="400" autostart="false" />

And the actual player (the video is a music video by Rise Against singing Prayer of the Refugee):

Update: As Steve has pointed out below in the comments, since JW FLV Media Player also supports extensions such as SWF, MP3, H.264, JPG, GIF, and PNG, streams, and playlists, you can also use them using WP-FLV. Just replace the href attribute with the desired source.

email this

Add to deli.cio.us

Digg it

Permalink

22 Comments

Subscribes to Rss Feeds

get latest updates on site news and site post

About

First off, thank you for visiting my blog. Second, thanks for reading this About section (as most people simply ignore the garbage in the sidebar). This truly is just another tech blog (if you missed the "slogan" above. Browse through this blog, and all you'll pretty much see are step-by-step tutorials, helps, and FAQs mainly about web designing and programming. If you're lucky you might stumble across a random post but other than that, not much. Anyway, I hope you enjoy your stay.

Tags

css embed flv images jw flv media player preload valid wordpress wp-flv

Search

Recent Entries

  • Converting Numbers to Alphabets in PHP
  • Preloading Images with Valid CSS
  • Embedding FLV in WordPress

Recent Comments

  • recepti » Embedding FLV in WordPress
  • malbert75 » Embedding FLV in WordPress
  • Malcolm » Embedding FLV in WordPress
  • daaune » Embedding FLV in WordPress
  • Preload rollover images in WordPres… » Preloading Images with Valid CSS
  • FLV players » Embedding FLV in WordPress
  • Newton Calegari » Embedding FLV in WordPress
  • Alvin » Preloading Images with Valid CSS
  • brian » Preloading Images with Valid CSS
  • Lucky-1 » Preloading Images with Valid CSS

Most Commented

  • Embedding FLV in WordPress (22)
  • Preloading Images with Valid CSS (7)

Categories

  • Uncategorized
  • computers
  • scripts
  • mods
  • css
  • web design

Meta

  • Log in
  • Wordpress Themes

Recent Comments

  • recepti » Embedding FLV in WordPress
  • malbert75 » Embedding FLV in WordPress
  • Malcolm » Embedding FLV in WordPress
  • daaune » Embedding FLV in WordPress
  • Preload rollover images in WordPres… » Preloading Images with Valid CSS
  • FLV players » Embedding FLV in WordPress
  • Newton Calegari » Embedding FLV in WordPress
  • Alvin » Preloading Images with Valid CSS
  • brian » Preloading Images with Valid CSS
  • Lucky-1 » Preloading Images with Valid CSS

Monthly Archives

  • April 2008
  • March 2008
  • February 2008

Daily Archives

  • April 9, 2008
  • March 16, 2008
  • February 18, 2008

Links

  • Development Blog
  • Documentation
  • Plugins
  • Suggest Ideas
  • Support Forum
  • Themes
  • WordPress Planet

Counter

  • Hit count: 699
©2006-2008 Alvin’s Blog
Designed by Elegant WP Themes
Valid XHTML and Valid CSS