Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

LSL-2-PHP Library

Craze Copeland
Registered User
Join date: 25 Mar 2006
Posts: 19
09-17-2006 12:45
What it does:
I have created a PHP library which includes 24 LSL functions, that have been re-written in PHP. Since PHP does not have real 3d objects, I couldn't include some of the most practical ones.

How to use it:
Just upload the file (lsl2php.lib.php) to your server, and then include it at the top of any php document that you plan on using the library with. EXAMPLE: include('lsl2php.lib.php');

Download:
http://www.badongo.com/file/1423629
http://rapidshare.de/files/33481994/lsl2php.lib.zip.html

Source/Functions:
CODE
<?php

// ==========================================================================
// ==========================================================================
// --------------------------------------------------------------------------
// Title: LSL-2-PHP Library
// Version: 1.0
// Author: craze3
// Email: craze3@gmail.com
// Description: Linden Scripting Language functions, recreated in PHP.
// Filename: lsl2php.lib.php
// License: GNU/LGPL
// Date: September 2006
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// EXAMPLES:
// include('lsl2php.lib.php');
// include('/lsl2php.lib.php');
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Functions/Syntax/Description:
// -----------------------------
// llDialog(message); - Opens a javascript alert window with the message.
// llSay(message); - Prints the message on to the page.
// llShout(message); - Prints the message on to the page in bold.
// llWhisper(message); - Prints the message on to the page in italic.
// llMD5String(message); - Returns the message encrypted as a MD5 hash.
// llEmail(address, subject, message); - Sends an email to address, with the specified subject and message.
// llDetectedKey(); - Returns the user's ip address.
// llGetNumberOfNotecardLines(file); - Returns the amount of lines in a file.
// llGetNotecardLine(file, line); - Returns the specified line from the specified file.
// llTeleportAgentHome(); - Redirects the user to their homepage.
// llGetDate(); - Returns the date in m/d/Y format.
// llGetGMTClock(); - Returns the UTC time.
// llList2String(list, index); - Returns the list entry specified by index.
// llDie(); - Exits the script. Anything past this line will not be executed.
// llToUpper(message); - Changes all the letters in message to uppercase.
// llToLower(message); - Changes all the letters in message to lowercase.
// llStringLength(message); - Returns the length of message.
// llGetSubString(message, start, end); - Returns a substring of message, starts and ends at specified.
// llSubStringIndex(message, pattern); - Finds pattern in message and returns the index.
// llFrand(maximum); - Generate a random number between 0 and the maximum specified.
// llInsertString(destination, position, source); - Inserts source into destination at position.
// llLoadURL(destination); - Redirects the user to destination.
// llSetText(title); - Used to set the title of the webpage.
// llSleep(seconds); - Delays the script for the specified amount of seconds.
// --------------------------------------------------------------------------
// ==========================================================================
// ==========================================================================

function llDialog($message){
echo "<script language='javascript'>alert(\"$message\");</script>";
}

function llSay($message){
echo $message;
}

function llShout($message){
echo "<b>$message</b>";
}

function llWhisper($message){
echo "<i>$message</i>";
}

function llMD5String($message){
return md5($message);
}

function llEmail($address, $subject, $message){
$ip = GetHostByName($REMOTE_ADDR);
if(mail($address, $subject, $message, 'From: $ip@lsl2php.craze3.com')){
return true;
}
else{
return false;
}
}

function llDetectedKey(){
$ip = GetHostByName($REMOTE_ADDR);
return $ip;
}

function llGetNumberOfNotecardLines($notecard){
$fd = fopen ($notecard, "r");
while (!feof ($fd))
{
$buffer = fgets($fd, 4096);
$lines[] = $buffer;
}
fclose ($fd);
return count($lines);
}

function llGetNotecardLine($notecard, $line){
$fd = fopen ($notecard, "r");
while (!feof ($fd))
{
$buffer = fgets($fd, 4096);
$lines[] = $buffer;
}
fclose ($fd);
return $lines[$line];
}

function llTeleportAgentHome(){
header("Location: javascript:window.home()");
}

function llList2String($array, $index){
return $array[$index];
}

function llDie(){
exit();
}

function llGetDate(){
return date("m/d/Y");
}

function llGetGMTclock(){
return time();
}

function llToLower($message){
return strtolower($message);
}

function llToUpper($message){
return strtoupper($message);
}

function llStringLength($message){
return count($message);
}

function llGetSubString($message, $start, $end){
return substr($message, $start, $end);
}

function llSubStringIndex($message, $pattern){
return strpos($message, $pattern);
}

function llFrand($max){
return rand(0, $max);
}

function llInsertString($intostring, $offset, $insertstring) {
$part1 = substr($intostring, 0, $offset);
$part2 = substr($intostring, $offset);

$part1 = $part1 . $insertstring;
$whole = $part1 . $part2;
return $whole;
}

function llLoadURL($url){
header("Location: $url");
}

function llSetText($title){
echo "<script language=\"javascript\">document.title = \"$title\";</script>";
}

function llSleep($seconds){
sleep($seconds);
}

//These are test lines I used to test the functions when I was coding. They are commented out and not executing.
//llSay("Hello!<br>");
//llShout("I'm yelling from over here!<br>");
//llSay(llMD5String("Hello there!") . "<br> frf <br>");
//llSay(llGetNumberOfNotecardLines("hk.txt") . " - " . llGetNotecardLine("hk.txt", 27) . "<br>");
//$candy = array('blue', 'red', 'green');
//llSay(llList2String($candy, 2));
//llInsertString("abcdef", 3, "123"); // returns "abc123def"


?>
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
09-19-2006 08:42
/54/4e/138489/1.html
_____________________
i've got nothing. ;)