php-general Digest 18 Sep 2006 03:38:26 -0000 Issue 4353

Topics (messages 241871 through 241875):

Re: loadHTML/loadHTMLFile - DOM functions
        241871 by: Rob
        241872 by: Leonidas Safran
        241874 by: Rob

DOMDocument->saveXML()
        241873 by: Chris Boget

Links Request From [EMAIL PROTECTED]
        241875 by: Avenger

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Leonidas Safran wrote:
 > I tried following:

I downloaded the ominous html page, coded it as UTF-8 (with text-editor option) 
and added a metag-tag declaring utf-8 encoding:
<meta http-equiv = 'content-type' content = 'text/html; charset=UTF-8'>

I checked that the special characters were written correctly then (actually I had to correct them).
Then I used the function:
$doc = new DomDocument('1.0', 'UTF-8');

The result is still the same, special chars are displayed wrong. Different wrong than before :-) 
but still wrong... ("ä" is now "ä").

I tried analogy to do the same with "ISO-8859-1" but it's not getting better...

So, fazit, even converting the whole document in UTF-8 and adding UTF-8 charset 
declaration to it, doesn't help me handling special chars...

And what about the img-tags which are converted into what ever invisible chars 
(empty spaces looking at the source code)...?

Do you have your code somewhere?

Another thing I realized that I failed to mention before is that
using saveXML($element) will serialize the full element, but outputs it in UTF-8 encoding. Have you tried converting the output of that to the encoding of the original HTML page?

Rob

--- End Message ---
--- Begin Message ---
Hello Rob,

> Do you have your code somewhere?

Yes, I paste it below. There are two files, one for HTML output (which I make 
invisible with style declaration "display:none;" and the second file is a 
javascript function which is supposed to output the content...

Another thing I realized that I failed to mention before is that
using saveXML($element) will serialize the full element, but outputs it in 
UTF-8 encoding. Have you tried converting the output of that to the encoding of 
the original HTML page? 

Well, I don't know any charset converting function which would be from standard 
library...


Here are the two files...

Thank you for your time...

LS


####################
code (1)
####################

class Stocks{

  var $doc;
  //var $source = Array("name" => "börse24", "url" => 
"http://boerse.n24.de/n24/kurse_listen.htm?sektion=TECDAX&awert=DEUTSCHLAND&u=0&k=0";);
  var $source = Array("name" => "börse24", "url" => "../data/file.html");
        
  var $ticker = "";

  function Stocks(){

    $this->doc = new DomDocument('1.0', 'UTF-8');
    //$this->doc->validateOnParse = true;
                
    $file = file_get_contents($this->source["url"]);
                
    //$file = preg_replace("/<img ([^>]*)>/", "", $file);
    $file = preg_replace("/&nbsp;/", "", $file);
    //$file = preg_replace("/±/", "&plusmn;", $file);
                
    $this->doc->loadHTML($file);
        
    $elements = $this->doc->getElementsByTagName("tr");
                
    $i = 0;             
                
    while( $elements->item($i) ){
                        
      if( $elements->item($i)->hasAttributes() && preg_match("/td[0|1]/", 
$elements->item($i)->getAttribute("id")) > 0 ){
                                
        $child_elements = $elements->item($i)->childNodes;
                        
        $j = 0;
        //$x = 0;
                                
        $this->ticker .= "<div name = 'stock'>\n";
                                
        while( $child_elements->item($j) ){     
          $this->ticker .= $child_elements->item($j)->textContent;
          if( $j == 4 ){
            $this->ticker .= " €";
          }                                     
          $this->ticker .= "--sep--";
          $j++;                                 
        }                                                       
        $this->ticker .= "</div>\n";
      }                 
      $i++;
    }
        
  $this->show();
        
  }
        
  function show(){      
    echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 
Transitional//EN\"\n\"http://www.w3.org/TR/html4/strict.dtd\";>";
    //echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" 
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\";>\n";
    echo "<html>\n";
    echo "<head>\n";
    echo "<title>TecDax</title>\n";
    echo "<script src = '../javascript/tecdax.js' type = 
'text/javascript'></script>\n";
    echo "<meta http-equiv = 'content-type' content = 'text/html; 
charset=UTF-8'>\n";
    echo "</head>\n";
    echo "<body onLoad = 'getAllStocks();showAllStocks();'>\n";         
    echo "<div style = 'display:none;' id = 'tecdax'>\n";
    echo $this->ticker . "\n";
    echo "</div>\n";
    echo "</body>\n";
    echo "</html>\n";
  }
}

$stocks = new Stocks();


####################
code(2)
####################

/*
functions for tecdax stocks ticker
*/

var tecdax = "";

function getAllStocks(){
  tecdax = document.getElementById("tecdax").innerHTML;
}

function showAllStocks(){

  var stocks = document.getElementsByName("stock");
  var stock = new Array();
        
  for( i = 0 ; i < stocks.length ; i++ ){
                
    stock[i] = new Array();
    var tmp_stock = new Array();
    tmp_stock[i] = stocks[i].innerHTML;
                
    var attributes = tmp_stock[i].split("--sep--");
                
    var x = 0;
        
    for( j = 0 ; j < attributes.length ; j++ ){
                                
      var result = attributes[j].match(/\w/gi);                 
        
      if( ! result ){
        continue;
      }else{
        //attributes[j].replace(/[Â|±]+/,"");
        stock[i][x] = attributes[j] + " ";                              
        x++;
      }

    }
                
    alert(stock[i]);
                
  }
        
document.getElementById("tecdax").innerHTML = stock[0] + " " + stock[1];
document.getElementById("tecdax").style.fontSize = "11px";
document.getElementById("tecdax").style.display = "inline";
}

-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

--- End Message ---
--- Begin Message ---
Leonidas Safran wrote:
Hello Rob,

Do you have your code somewhere?

Yes, I paste it below. There are two files, one for HTML output (which I make invisible 
with style declaration "display:none;" and the second file is a javascript 
function which is supposed to output the content...

Try this line:

$this->ticker .= utf8_decode($child_elements->item($j)->textContent);

Your original HTML document is ISO-8859-1, so when you want the text I think you want to convert the UTF-8 (Internally DOM document works with UTF-8) to ISO-8859-1. Just using the utf8_decode function here from ext/xml. This elminates those  characters you were getting.

Rob

--- End Message ---
--- Begin Message --- I looked all through the documentation but was unable to find out if this was possible and, if so, how. When you call ->saveXML(), it prints out the XML declaration <?xml version="1.0"?> alont with the structure of the document. Is there any way to suppress that? I'm trying to print out extra text (in the form of a stylesheet call) and the declaration that ->saveXML() prints out is messing everything up.

Would it be possible to point to the relevant page in the documentation that discusses how to do this?

thnx,
Chris
--- End Message ---
--- Begin Message ---
Dear Webmaster:

PhpMore is a chinese PHP community focus on professional php
programers in China.
phpmore.com , the club of phpmore , is a digg-like site where
programers share their expericence.
phpmore also hold a chinese PHP e-mag named PHP&MORE from year 2004 ,
it published totally 6 vols from then on.
Now, we want to put a link on php.net's link page , in "Non-English
PHP Sites" section.

so more chinese php programer can join together , to discus and share
their tech .
can you so kind to do this? if not , plz tell us how we can do this.Thx.

Best,

--
From avenger

--- End Message ---

Reply via email to