phayes / geoPHP

Advanced geometry operations in PHP
https://geophp.net
Other
861 stars 262 forks source link

Authorize the use of domNode directly in geomFromText methods #82

Open jcornet opened 11 years ago

jcornet commented 11 years ago

I use geoPhp and domDocument to parse (or write) gpx or kml files. First, thank you for this great API !

It would be great to allow direct use of domNode in geomFromText methods (for xml formats). Currently, my classes transform a domNode into a string to be able to use geoPhp geomFromText but this method transform this string into domNode again

I propose this replace in geomFromText methods :

Replace

// Change to lower-case, strip all CDATA, and de-namespace
$text = strtolower($text);
$text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s','',$text);

// Load into DOMDOcument
$xmlobj = new DOMDocument();
@$xmlobj->loadXML($text);
if ($xmlobj === false) {
  throw new Exception("Invalid GeoRSS: ". $text);
}

$this->xmlobj = $xmlobj;

with

if(is_string($text)){
    // Change to lower-case and strip all CDATA
    $text = mb_strtolower($text, mb_detect_encoding($text));
    $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s','',$text);

    // Load into DOMDOcument
    $xmlobj = new DOMDocument();
    @$xmlobj->loadXML($text);
    if ($xmlobj === false) {
      throw new Exception("Invalid KML: ". $text);
    }

    $this->xmlobj = $xmlobj;
}
else if(is_object($text))
    $this->xmlobj = $text;
else
    return false;
jcornet commented 11 years ago

In fact, this code doesn't work because of case issues....