0

so I have multiple HTML files which I need to get some praticular data from, I mean theres a bunch of non relative information in this HTML files, but I need just lets say things that are between the <div class="myInfo"> and </div>, after getting this information I want to handle it in my own PHP page, so for example I can insert this data into some variables. Is it even possible using PHP only? (Forgive me for my English mistakes)

animuson
  • 53,861
  • 28
  • 137
  • 147
SnirD
  • 708
  • 11
  • 22
  • 1
    Do you have some samples of the data you wish to process? Have you tried anything as of yet? (If so, explain what, and what went wrong) Are you familiar with PHP HTML libraries such as Simple HTML Parser (http://simplehtmldom.sourceforge.net/)? What about using regular expressions? – gpmcadam Jun 08 '10 at 02:03
  • 1
    possible duplicate of [Robust, Mature HTML Parser for PHP](http://stackoverflow.com/questions/292926/robust-mature-html-parser-for-php) – Ian Varley Jun 08 '10 at 02:04
  • @Baur - Is is not smart to use regular expressions to parse html. – Oren Hizkiya Jun 08 '10 at 02:06
  • 1
    @Oren: I understand that, however, firstly: I was trying to engage the asker in dialogue to understand what (s)he had attempted; secondly: I wasn't necessarily suggesting that the HTML itself should be parsed using regular expressions. The intent of the asker was initially unclear (see the previous revisions: http://stackoverflow.com/posts/2994339/revisions) and if it was a case of simple-language parsing that was needed, then regular expressions wouldn't be a *bad* solution. – gpmcadam Jun 08 '10 at 02:09
  • @Bauer - I apologize for my jumpiness in restating the popular StackOverflow catch phrase. I hope the original poster has found what he is looking for. – Oren Hizkiya Jun 08 '10 at 02:12
  • The SimpleDom solution works great for me. Much appreciate your help. – SnirD Jun 08 '10 at 02:30

2 Answers2

2

I would use SimpleDom

http://simplehtmldom.sourceforge.net/

// Find all article blocks
foreach(file_get_html('http://smysite.com')->find('div.myInfo') as $Info) {
    print_r($Info);
}

Alternative. http://php.net/manual/en/book.simplexml.php

RobertPitt
  • 56,863
  • 21
  • 114
  • 161
  • This is the ultimate tool for DOM Parsing. along side PHP's XMLDOM Functions,, but this is a simple easy starter - i updated post because i posted incorrect link. please review – RobertPitt Jun 08 '10 at 02:19
  • That's working just great, this tool is very powerful, thanks. – SnirD Jun 08 '10 at 02:29
0

I think you need to use CURL for that

Here is a link http://www.php.net/manual/en/book.curl.php

Starx
  • 77,474
  • 47
  • 185
  • 261