asimlqt / php-google-spreadsheet-client

A PHP library for accessing and manipulating Google Spreadsheets
Other
543 stars 154 forks source link

getByTitle() outputs mangled UTF-8? #85

Closed nekromoff closed 9 years ago

nekromoff commented 9 years ago

Darčekové kódy instead of Darčekové kódy

therefore I am unable to match correct UTF-8 and this function returns null.

nekromoff commented 9 years ago

fixed by adding this function so it's easy to fetch by spreadsheet URL / ID:

    /**
     * Gets a spreadhseet from the feed by its ID.
     *
     * @param string $title
     *
     * @return \Google\Spreadsheet\Spreadsheet|null
     */
    public function getByID($ID)
    {
        foreach($this->xml->entry as $entry) {
            if($entry->id->__toString() == $ID) {
                return new Spreadsheet($entry);
            }
        }
        return null;
    }
asimlqt commented 9 years ago

I've just tested this and it works fine:

$service = new SpreadsheetService(); $spreadsheetFeed = $service->getSpreadsheets(); $spreadsheet = $spreadsheetFeed->getByTitle("Darčekové kódy"); echo $spreadsheet->getTitle()."\n";

It outputs the title correctly in utf-8.

Also there is no need to fetch a list of spreadsheets if you know the id of the spreadsheet you want. This method is already available in the SpreadsheetService class.

@see https://github.com/asimlqt/php-google-spreadsheet-client/blob/master/src/Google/Spreadsheet/SpreadsheetService.php#L50