1583 posts
Location
Germany
Posted 20 May 2013 - 06:04 PM
Hello everybody,
I have started programing PHP.
Now here is my question:
Can I have a lua function to read the content of an webpage. The content looks like this:
<first item>
Name = test
ID = 1
</first item>
<second item>
Name = test two
ID = 2
</second item>
And save it like this table:
local content = {
["first item"] = {Name = "test", ID = "1"},
["second item"] = {Name = "test two", ID = "2"}
}
Is this possible?
1522 posts
Location
The Netherlands
Posted 20 May 2013 - 06:22 PM
That is definitely possible. I would say leave the name and ID, wich looks like this:
<block>
thenameofchoice
654
</block>
first of all we want to put all the contents of the site in a table:
local response = http.get('http://www.server.de') -- see what I did here?;p
local lines = {}
if response then
for l in response.readLine do
table.insert(lines, l)
end
end
When you find a <block> you know you are getting first a name and then an ID.
You can probably do the rest yourself ^^
Edit: you want to search for an opening tag of course ( < )
1583 posts
Location
Germany
Posted 20 May 2013 - 06:34 PM
That is definitely possible. I would say leave the name and ID, wich looks like this:
<block>
thenameofchoice
654
</block>
first of all we want to put all the contents of the site in a table:
local response = http.get('http://www.server.de') -- see what I did here?;p
local lines = {}
if response then
for l in response.readLine do
table.insert(lines, l)
end
end
When you find a <block> you know you are getting first a name and then an ID.
You can probably do the rest yourself ^^
Edit: you want to search for an opening tag of course ( < )
Thx!
Only one question:
Is it possible to remove the "<" and the ">" after reading it in lua ?
992 posts
Posted 20 May 2013 - 07:21 PM
there is probably a better way but
string.sub(sText,2,#sText-1)