Jump to content




Variable Blocks


  • You cannot reply to this topic
3 replies to this topic

#1 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 20 May 2013 - 05: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?

#2 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 20 May 2013 - 05: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 ( < )

#3 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 20 May 2013 - 05:34 PM

View PostEngineer, on 20 May 2013 - 05:22 PM, said:

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 ?

#4 BigSHinyToys

  • Members
  • 1,001 posts

Posted 20 May 2013 - 06:21 PM

there is probably a better way but
string.sub(sText,2,#sText-1)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users