Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: 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');



// ==========================================================================
// ==========================================================================
// --------------------------------------------------------------------------
// 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
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// 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;
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(){

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){

//These are test lines I used to test the functions when I was coding. They are commented out and not executing.
//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
Original Thread
09-19-2006 08:42
i've got nothing. ;)
paulie Femto
Into the dark
Join date: 13 Sep 2003
Posts: 1,098
09-19-2006 09:27
So, this allows an alternate, web-based, client to interact with SL and perform some LSL functions?
REUTERS on SL: "Thirty-five thousand people wearing their psyches on the outside and all the attendant unfettered freakishness that brings."
Thraxis Epsilon
Registered User
Join date: 31 Aug 2005
Posts: 211
09-19-2006 10:15
It allows you to simulate LSL scripts in a web page
Strife Onizuka
Join date: 3 Mar 2004
Posts: 5,887
09-19-2006 13:43
The llMD5String function listed above won't work the same way
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Guido Columbia
Registered User
Join date: 25 Oct 2005
Posts: 102
09-19-2006 15:09
Neat idea, good job. =)
Craze Copeland
Registered User
Join date: 25 Mar 2006
Posts: 19
09-19-2006 16:00
Not all of them work the same.
Aliqui Ennui
Registered User
Join date: 16 Jul 2005
Posts: 6
11-08-2006 22:14
With md5 string you forgot the salt. I recommend going back to the LSL wiki and understanding them all thoroughly. This is one among other inconsistensies.
Imp Xi
Registered User
Join date: 6 Oct 2006
Posts: 15
01-16-2007 22:45
The two functions I need most for a PHP application I'm planning are:


If I had those two, I'd be able to easily store/retrieve lists from MySQL.

(There's probably a MUCH easier way... I just haven't thought of it.)
Charles Granville
Registered User
Join date: 18 Mar 2006
Posts: 33
01-17-2007 11:36
Use explode() and implode().