Home html Help Silence HTML

Help Silence HTML

Author

Date

Category

Help please stealing HTML.
I need to make data into an array for this principle:

$ MAS [0] = Array (00094318,4,500, ID5869445320,2014-08-03 & amp; nbsp; 14: 48 );
$ Mas [1] = Array (00094366,5,500, ID58694453765,2014-08-03 & amp; NBSP; 14: 48);

I tried to strange:

preg_match_all ('/ \ \ & lt; td class = "td [0-9] (text_right) {0,1}" \ & gt; (.) {0,} \ & lt; \ / td \ & gt; / u ', $ HTML, $ DATA);

But my option is not entirely correct.

& lt; table class = "table2" cellpadding = "0" CellSpacing = "0" & ​​gt;
& lt; TR class = "TR_HEAD" & gt;
& lt; TD Class = "TD_Head" & gt; sender & lt; / td & gt;
& lt; td class = "TD_Head" style = "width: 70px" & gt; amount, rub. & lt; / TD & GT;
& lt; TD Class = "TD_Head" style = "width: 310px" & gt; Comment & LT; / TD & GT;
& lt; td class = "TD2" & gt; date & lt; / td & gt;
& lt; / tr & gt;
& lt; tr class = "tr1" onmouseover = "onmouseOver (this, '')" onmouseout = "onmouseout (this, '', 'tr1')" & gt;
& lt; TD Class = "TD1" & gt; 00094318 & lt; / td & gt; & lt; td class = "TD1 text_right" & gt; 4 500 & lt; / td & gt;
& lt; TD Class = "TD1" & gt; ID5869445320 & LT; / TD & GT;
& lt; TD Class = "TD2" & gt; 2014-08-03 & amp; NBSP; 14: 48 & lt; / td & gt;
& lt; / tr & gt;
& lt; tr class = "tr1" onmouseover = "onmouseOver (this, '')" onmouseout = "onmouseout (this, '', 'tr1')" & gt;
& lt; TD Class = "TD1" & gt; 00094366 & lt; / td & gt; & lt; td class = "TD1 text_right" & gt; 5 500 & lt; / td & gt;
& lt; TD Class = "TD1" & gt; ID58694453765 & lt; / td & gt;
& lt; TD Class = "TD2" & gt; 2014-08-03 & amp; NBSP; 14: 48 & lt; / td & gt;
& lt; / tr & gt;
& lt; tr class = "tr 6" & gt;
& lt; TD Class = "Padding_5_0 TD2" & gt; number of operations: & lt; b & gt; 1 & lt; / b & gt; & lt; / td & gt;
& lt; TD Class = "TD2 Text_right Bold" & gt; 4 500 & lt; / td & gt;
& lt; TD & GT; & LT; / TD & GT;
& lt; TD & GT; & LT; / TD & GT;
& lt; / tr & gt;
& lt; / Table & gt;

Answer 1, Authority 100%

Poule HTML with the help of regulators, in my opinion and look very many is a perversion. For such things there are appropriate tools: PHP Simple HTML DOM PARSER or phpquery (examples Find here ), or even with the help of the built-in PHP. Here is your task implemented using domdocument and without connecting any other third-party libraries:

$ doc = new domdocument ();
$ Doc- & GT; Loadhtmlfile ("file.html"); // Path to your file
$ table = $ doc- & gt; GetElementsBytagname ('Table');
$ Data = Array ();
$ i = 0;
Foreach ($ table- & gt; item (0) - & gt; GetElementsByTagname ('TR') AS $ TR) {
  Foreach ($ TR- & GT; GetElementsBytagname ('TD') AS $ TD) {
    $ Data [$ i] [] = HTMLENTIES (UTF8_DECODE ($ TD- & GT; NodeValue), ent_quotes, 'UTF-8');
  }
  $ i ++;
}
Print_R ($ Data);

Result:

array
(
  [0] = & gt; Array.
    (
      [0] = & gt; Sender
      [1] = & gt; Amount, rub.
      [2] = & gt; A comment
      [3] = & gt; the date of the
    )
  [1] = & gt; Array.
    (
      [0] = & gt; 00094318.
      [1] = & gt; 4 500.
      [2] = & gt; ID5869445320.
      [3] = & gt;
    )
  [2] = & gt; Array.
    (
      [0] = & gt; 00094366.
      [1] = & gt; 5 500.
      [2] = & gt; ID58694453765.
      [3] = & gt;
    )
  [3] = & gt; Array.
    (
      [0] = & gt; Number of operations: 1
      [1] = & gt; 4 500.
      [2] = & gt;
      [3] = & gt;
    )
)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions