Wednesday, June 20, 2007

Ah... stuff.

Hello everyone! I'm here again with some coding updates and stuff.

Well, My Videos version 1.2 just finished up. With this version I finally added more than just Youtube to the sites you could use videos from. I got a lot of suggestions for sites but couldn't figure out how they embedded it, meaning they didn't provide it easily, and I didn't care enough to go snoop around to figure it out. I figured if they didn't have a box to let me copy it, then it wasn't worth it.

Anyway, the two that I did add were Dailymotion and Veoh. So now when you submit a video you can choose which site your video is from. Another thing I added was instructions on how to get the code for each site. The code is crucial for the video to work, so I felt that my previous instructions weren't very clear, so I wrote up some and packaged them with the new version. Another thing I did was an excessively unnecessary way to write the version. I'll show you this code now (I hope this thing indents properly):


$version = $_GET['version'];

$i = 0;

$arr = array();

while ($i < strlen($version))
{
$arr[] = $version{$i};
$i++;
}

$ver_string = '';

$i = 0;

foreach ($arr as $v)
{
if ($i != 0)
{
$ver_string .= '.';
}

$ver_string .= $v;

$i++;
}

echo $ver_string;

?>

Now, when you go to this page, the URL looks like http://yourboard.com/forum/my_vids/index.php?version=120 (120 is for version 1.2.0). Instead of having to edit this file for each new version, I put this link in the lang_my_vids files right next to the version so I edit those two now. I'll now go over what this code does.

First off it gets the version value from the URL and sets it into the version variable. Next it makes a counter variable which will be used quite a bit. It then defines an array. What the while statement checks for is that counter variable versus the length of the version string. What happens next is the next open slot in the array is given the value of the version string at position i. So in the first pass, $arr[0] = 1 is basically what is happening. Then i is incremented to keep it going.

Now I make a new variable and set i back to 0. We're almost done! Now then, I love foreach because it is the best way to traverse an array (I think so at least). In this instance I have no need for the key so I just use $arr as $v. What happens in a foreach is for this type you do foreach (array as value), where value is the value of the array at that position. foreach allows you to go through associative arrays easily. So first off it checks if i isn't 0. If it's not (meaning that you're no longer in the first position), then it'll add a period before the number. Then the value is added onto ver_string and i is incremented. Finally, the version string is printed out.

Logic Process:

$version = 120;
$i = 0;
$arr = array();

WHILE
-$arr[0] = 1;
-$i = 1;
-$arr[1] = 2;
-$i = 2;
-$arr[2] = 0;
-$i = 3;
-3 is not less than 3

$ver_string = '';
$i = 0;

FOREACH
-IF
--0 equals 0 (body not executed)
-$ver_string = '1';
-$i = 1;
-IF (1 does not equal 0)
--$ver_string = '1.';
-$ver_string = '1.2';
-$i = 2;
-IF
--$ver_string = '1.2.';
-$ver_string = '1.2.0';
-$i = 3;
No more values in array

Prints out 1.2.0

That's it for that code! Yeah, pretty unnecessary, but whatever :)

Anyway, I plan on working on Signature of the Week version 2 soon. I'm going to completely re-write it so it'll look nicer, have comments, and should be more efficient. This will probably take a while, so be patient. Although really it doesn't seem as though people are crazy about it... It bothers me that in the competition for May on IZE that a mod that someone just updated and didn't even write themselves is doing better than mine, which I did all myself and was my first mod, and it's in the large mods category. Rawr.

I think that's all for today, I hope to make more of these kind of updates for those who want to learn some programming :)

Oh, and my tutorial is coming along, I just forgot about it for a little while, but I'll get it done.

Until next time,
Bye!

2 comments:

Anonymous said...

This blog is null untill it meets required standards :p

Bryan said...

$mikel = NULL;

echo ":P";