• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

PHP oder Word Dokument uploaden und Wörter auszählen

nordmann

Neues Mitglied
Hallo zusammen!

Ich möchte Word oder PDF Dokumente hochladen und "online" die Wortanzahl (ohne Interpunktion) ermitteln und ausgeben.

Gibt es da schon Lösungsansätze?

Ich danke Euch für Eure Hilfe!;heart

Gruß
Nordman
 
Sollen wir deine Hausaufgaben erledigen?

Google <--

Es gibt eine Menge Menschen, die eine Menge Wissen in der Schublade haben und dieses Wissen mit anderen teilen (können).
Wenn Du jedesmal, wenn Du mit dem Auto fahren willst das Auto neu erfinden musst, ist ja auch blöd, oder?
Bevor ich Auto fahren will, frage ich nette Menschen ob Sie das Auto vielleicht schon erfunden haben!
Wenn nicht baue ich halt ein Auto und nehme dann durchaus andere Menschen mit, frei nach dem Motto "Dum Spiro Spero" und nicht "Mundus vult decipi. Ergo decipiatur" ("Solange ich atme hoffe ich" und "Die Welt will betrogen sein, darum sei sie betrogen")

Ich wünsche ein schönes Wochenende!:mrgreen:

Gruß
Jörg
 
Du kannst mit PHP nicht direkt in einem Word Dokument suchen. Du musst die Datei mit Word öffnen und als Textdatei abspeichern oder in deine DB schreiben.
Dazu benötigst du aber Root-Zugriff und musst auf deinem Server Word installiert haben.

Wie bereits vitus37 sagte dann mit str_word_count() arbeiten.

Gruß
Michael

PHP:
<?php
    // msword.inc.php

    // NOTE: Using COM with windows NT/2000/XP with apache as a service
    // - Run dcomcnfg.exe
    // - Find word application and click properties
    // - Click the Security tab
    // - Use Custom Access Permissions
    //      - Add the user who runs the web server service
    // - Use Custom Launch permissions
    //      - Add the user who runs the web server service

    $wdFormatDocument = 0;
    $wdFormatTemplate = 1;
    $wdFormatText = 2;
    $wdFormatTextLineBreaks = 3;
    $wdFormatDOSText = 4;
    $wdFormatDOSTextLineBreaks = 5;
    $wdFormatRTF = 6;
    $wdFormatUnicodeText = 7;
    $wdFormatHTML=8;

    class MSWord
    {
        // Vars:
        var $handle;

        // Create COM instance to word
        function MSWord($Visible = false)
        {
            $this->handle = new COM("word.application") or die("Unable to instanciate Word");
            $this->handle->Visible = $Visible;
        }

        // Open existing document
        function Open($File)
        {
            $this->handle->Documents->Open($File);
        }

        // Create new document
        function NewDocument()
        {
            $this->handle->Documents->Add();
        }

        // Write text to active document
        function WriteText( $Text )
        {
            $this->handle->Selection->Typetext( $Text );
        }

        // Number of documents open
        function DocumentCount()
        {
            return $this->handle->Documents->Count;
        }

        // Save document as another file and/or format
        function SaveAs($File, $Format = 0 )
        {
            $this->handle->ActiveDocument->SaveAs($File, $Format);
        }

        // Save active document
        function Save()
        {
            $this->handle->ActiveDocument->Save();
        }

        // close active document.
        function Close()
        {
            $this->handle->ActiveDocument->Close();
        }

        // Get word version
        function GetVersion()
        {
            return $this->handle->Version;
        }

        // get handle to word
        function GetHandle()
        {
            return $this->handle;
        }

        // Clean up instance with word
        function Quit()
        {
            if( $this->handle )
            {
                // close word
                $this->handle->Quit();

                // free the object
                //$this->handle->Release();
                $this->handle = null;
            }
        }
    };

?>
 
PHP kann zwar word nicht öffnen aber PHP kann sehrwohl doc datein in HTML umwandeln ;-) Das langt ja schon da brauchst du kein Word für installieren.. bzw. docx ist noch einfacher weil alles im XML Format ist
 
Zurück
Oben