PHP Function – Get the YouTube Video Id from a YouTube URL

Posted: June 11th, 2010 | No Comments

Here is how you can get the YouTube Video ID from a URL no matter how many extra parameters get passed along with it.

function getYouTubeIdFromURL($url)
{
  $url_string = parse_url($url, PHP_URL_QUERY);
  parse_str($url_string, $args);
  return isset($args['v']) ? $args['v'] : false;
}

Call it:

$youtube_id = getYouTubeIdFromURL("http://www.youtube.com/watch?v=jhjhkum-kq8&feature=related");
echo $youtube_id;

// jhjhkum-kq8

PHP Function to Display FBML

Posted: May 4th, 2010 | 2 Comments

I’ve noticed in user’s code throughout the Facebook forum that they often display their FBML by having to echo the whole section or even worse closing the PHP tags, displaying the FBML and then reopening the PHP (example below)

if (!$session) {
  $url=$facebook->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0));
?>
<fb:redirect url="<?= $url ?>" />
<?php
  exit;
}

So I thought I would write up a quick function to help this look a little cleaner.
I don’t recommend that you use this in all cases but it’s good to havehandy.

Read more »


Free PHP List Files in a Directory Script

Posted: March 19th, 2010 | No Comments

After finding a bunch of ugly scripts to display files in a directory, I finally created my own. It’s two simple files: index.php and icons.png. (might switch to .gif soon)  Grab the files at the address below and beautify your file listings.

Get it now at: http://www.halgatewood.com/free/file-directory-list/

I’ve also added a ‘freebies’ section to the lower right of the sidebar —–>
Check it out.

Read more »


eZPublish – Get Image File from Object using PHP

Posted: March 10th, 2010 | 2 Comments

Your doing some actually PHP in eZ Publish (in a module, class or whatever) and you need to find the image data for the Image Attribute of an object, here is what to do:

$node = eZContentObjectTreeNode::fetch( $node_id );
$dataMap = $node->dataMap();

$image_attribute = $dataMap['image'];
$image_array = $image_attribute->Content()->attribute('original');

$image_url = $image_array['url'];
  1. First get into the DataMap of your object or node.
  2. Change the ‘image’ of $dataMap['image'] to whatever the attribute_identifier of your image is.
  3. Change the ‘original’ of $image_pathobj->Content()->attribute(‘original‘); to whichever size of image you need to get.  The image array contents all the good information of that image, i.e. height, width, filesize, etc.
  4. Use the ‘url’ to get a full path to your image. Slap a “/” on the front or use ezurl() to display.

If you want to see the available image sizes, you can check them by debugging this value:

$image_sizes = $image_attribute->Content()->attributes();

Subtitles with FlowPlayer

Posted: January 18th, 2010 | No Comments

I recently built a subtitling system for a site that I am working on: khristos.org

It uses FlowPlayer with the built in Captions Plugin.  The interesting part is that I also built an admin section where clients can add the subtitles on their own. Click the image below to see what it looks like. You can also check out the video here.

FlowPlayer Captions Admin Interface

What’s also interesting is a Mashable article that explains how you can add Captions to your YouTube videos.

With the rising popularity of this subject and videos on the web, I figured it would be a good chance to give back to the community that has taken me so far.

Read more »