PDA

View Full Version : code snippets



bh2k
04-07-2005, 07:58 PM
For everyone who is a coding member here I think we should start a thread for basic snippets and other little coding tid bits. I really want to ask kazoo if there is a possibility that I can write some extra addons to this forum so we can help beginners with their code. For instance one that matches functions from PHP and provides a link to the manual.

This is a totally random snip that finds the ASCII of HOLYBIBLE and matches it as 666 thus proving in code HOLYBIBLE=666 :-p



for($s='HOLYBIBLE',$i=0,$n=0;$i<strlen($s);$n+=ord($s{$i}),$i++);print$n.'<br>';


Anything is cool to post. :D

Kazoo
04-08-2005, 05:00 AM
what kind of extra add ons do you have in mind?

bh2k
04-08-2005, 10:59 AM
For instance:

I write a code snippet for someone who is having a problem with something in their code, but I use a function the person has never heard of or used themselves. I want to make an addon that automaticallly takes functions that fit a regular expression string and turn them into a link that links to the function in the manual.

example:
This is an amazingly simple example but just to illustrate what I mean

<?php
$values = array('one','two','three','four');
$num = rand(0,count($values));
echo values[$num];
?>

Which after going through the function replacement code would come back as...

<?php
$values = array( (http://www.php.net/manual/en/function.array.php)'one','two','three','four');
$num = rand( (http://www.php.net/manual/en/function.rand.php)0,count($values));
echo values[$num];
?>

So if the person looking at the code has no idea what rand or array did they would automatically get links to the manual so they can see what they do.

matt9669
04-08-2005, 08:02 PM
Hmm - I'm thinking something along the lines of a VB function that does this automatically for code incased in the function. Something like, [ code = php ] (code) [ /code ] where the function would operate differently (link to a different function library/reference) based on the code type specified. You could start with PHP and add languages as time and resources permit.

Kazoo
04-08-2005, 08:05 PM
Let's see how this goes before we start messing with the forum coding ;)

matt9669
04-08-2005, 08:19 PM
Oops, too late, looks like I botched the whole database and sent a worm to a million computers, all traced back to XS . . . crap . . . :lol2:

By definition a function is a separate entity and does not affect other functions, so adding a new VB function would not affect the way the forums operate. That said, I'm in no hurry here, just thinking how to implement bh2k's idea :toast:

bh2k
04-08-2005, 08:52 PM
Yea, well I have to perfect the regular expression I'm using to find and replace these functions. Anyone who is good with regex care to help?