Recommend this page to a friend! |
table2arr | > | All threads | > | Advanced Cellparsing | > | (Un) Subscribe thread alerts |
|
Daniel Sepeur - 2006-05-12 16:34:32
Hello,
actually, i am working extremely intensive with table2arr.php. And actually, i had a problem to parse some cellinformations correct, wich came back from table2arr.php. For example: You are searching for an address-string wich is located in Table 1, Row 0, Cell 0. The content of this cell is e.g.: Mr. Nameless<br> Somestreet<br> 88888 SomeCity You can fetch this cell like this: $g=new table2arr($page); $g->getcells(1); $content = $g->cells[0][0]; In the variable $content is now saved the content of the cell you need. But it is also without any HTML-element wich shows you this: Mr. NamelessSomestreet88888 SomeCity If you would like to parse this, you will have a small problem :-) I have written a small extension for table2arr.php. If you are using this extension, you will be able to make your cellcontent parseable. But let me explain it step by step. 1. First of all you have to add the following 5 lines of code to table2arr.php directly after line 129. // Code to replace HTML-Code with something else wich you can parse later for($atw=0;$atw<count($content_replacer);$atw++) { list($toreplace,$replacer) = split("\|",$content_replacer[$atw]); $col=preg_replace("/$toreplace/","$replacer",$col); } In original, the block will shown like this. [...] 129. if ($span==0) $span=1; 130. $col=trim(preg_replace("'<[\/\!]*?[^<>]*?>'si","",$col)); 131. $col=htmlentities($col,ENT_QUOTES,"UTF-8"); [...] After my changes, the block shows like this: [...] if ($span==0) $span=1; // Code to replace HTML-Code with something else wich you can parse later for($atw=0;$atw<count($content_replacer);$atw++) { list($toreplace,$replacer) = split("\|",$content_replacer[$atw]); $col=preg_replace("/$toreplace/","$replacer",$col); } $col=trim(preg_replace("'<[\/\!]*?[^<>]*?>'si","",$col)); $col=htmlentities($col,ENT_QUOTES,"UTF-8"); [...] 2. After you made those changes, you go into line 95 wich looks like this [...] 95. function getcells($tabidx) [...] and change it to [...] function getcells($tabidx,$content_replacer) [...] 3. Save your table2arr.php and go to the script in wich you would like to parse a specific cell. Now you can call $g->getcells with given a table-index and an array of elements you would like to replace. My final example here shows like this: $g=new table2arr($page); // Now i create an arrray with all HTML-Code wich should be // replaced to a char of my choice. // The HTML-Code and the replacer should be delimited by // an pipe sign (|). $content_replacer=array("<br>|#"); // Now i call getcells with table index and // the array $content_replacer $g->getcells(1,$content_replacer); The content of Row 0, Cell 0 can now be splitted by #-signs For my example above, the cellcontent shows now Mr. Nameless#Somestreet#88888 SomeCity You can now split it by # sign. Hope, this helps in some cases :-) Daniel |
info at phpclasses dot org
.