aRo` automating your e-commerce

17Feb/08
This blog has been neglected due to the success of Solidshops.com

capture the encoding from the main XML file tag

To capture the encoding from the XML tag of the file. We need to read the first line, and pass it to the function to capture the encoding value.

The first line looks like this:

< ?xml version="1.0" encoding="utf-8"? >

The PHP code:

PHP:
  1. function readfirstline($file){
  2.    $fp = @fopen($file, "r");
  3.    $firstline = fgets($fp);
  4.    fclose($fp);
  5.    return $firstline;
  6. } 
  7. function get_attr(  $line ,$attr) {
  8.   $start = strpos($line,"$attr");
  9.   $linesubstr($line,$start);
  10.   $arr_enc = split("\"",$line);
  11.  
  12.   return $arr_enc [1];
  13. }
  14.  
  15. $path = "home/user/feeds/id.xml";
  16. $line= readfirstline($path);
  17.        
  18. echo get_attr(  $line ,"encoding");

Popularity: 4% [?]

Filed under: php, xml Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.