Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Find a String in HTML

Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
06-07-2008 08:51
If I were to do a HTTP request and get all the HTML code into an LSL script, how would I go about finding a particular string from a page?

I basically need to find something that says, for example, "id:" and then get the bit immediately after it (what the actual id is in this case). How would I go about doing this?

Thanks in advance for any help!
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Xhawkx Holden
Registered User
Join date: 1 Nov 2006
Posts: 86
06-07-2008 09:14
you will want to read up on
A.275. llSubStringIndex

integer llSubStringIndex(string source, string pattern);

Finds index in source where pattern first appears. Returns -1 if no match is found.

to locate the position in the string where Id: is, and then use
A.113. llGetSubString

string llGetSubString(string src, integer start, integer end);

Returns the indicated substring from src. The start and end are inclusive, so 0,length-1 would capture the entire string and 0,0 would capture the first character. Using negative numbers for start and/or end causes the index to count backwards from the length of the string, so 0,-1 would capture the entire string. If start is larger than end the sub string is the exclusion of the entries, so 6,4 would give the entire string except for the 5th character.

to fetch the value of Id:
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-07-2008 13:08
You won't be able to do this with most web pages I believe, unless you know what you want is close to the beginning of the content stream; there is a limit to the amount of data you an get in the HTTP response. I believe it is currently 2kB. See http://www.lslwiki.net/lslwiki/wakka.php?wakka=http_response
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
06-25-2008 07:57
(sorry for the late reply; seems I'm not receiving notification)

Poop. I've just tested a few pages and copied the data up to where I need it and saved it as a text file. I've done it on a few files and it seems to be consistently 3kb.

I see an alternative, but it introduces an extra layer of error: I could do it in PHP and have PHP process the URL that the LSL script wants and return the data to the script that way. I don't like it because it's just going to cause more problems, but I know how to do it with PHP already and with a 2kb limit then I may have no option anyway, unless anyone has any other great ideas?
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
06-25-2008 08:04
No that's pretty much it, you're going to have to go the PHP route. At least you're ahead of the game when it comes to PHP.


http://www.secondscripter.com
_____________________
My tutes
http://www.youtube.com/johanlaurasia
Cryas Tokhes
Great Googley Moogley...
Join date: 8 Feb 2006
Posts: 124
06-25-2008 16:45
Just create a starter and a terminator with the information that you want in between them.

<html>
<!-- blah blah blah blah blah-->
=+The information that you want here+=
<!-- blah boah blah blah blah-->
</html>

then in your LSL:

integer startindex = llSubStringIndex(body,"=+";);
integer endindex = llSubStringIndex(body,"+=";);
string blah = llGetSubString(body,startindex + 2,endindex - 1);

'blah' will be the information you want.

this should give you the general idea of what I am getting at, hope this helps.