Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 19 su 19
  1. #11
    siccome nel file di testo
    sono presenti stringhe nel seguente formato:

    AEM.MI;1,71;5/19/2006;17:28;+0,012;1,695;1,72;1,69;4889981

    codice:
    while (!feof($handle)) {
    	$userinfo = fscanf ($handle, "%s%f%s%s%s%f%f%f%f");
    	//AEM.MI;1,71;5/19/2006;17:28;+0,012;1,695;1,72;1,69;4889981
       	list ($Codice,$QPrezzo,$data,$ora,$varp,$varq,$Prezzomin,$Prezzomax,$Volumi ) = $userinfo;
       	echo "$Codice $QPrezzo $data $ora $varp $varq $Prezzomin $Prezzomax $Volumi
    ";
    }
    
    fclose($handle);
    con questa soluzione il file stampato è uguale al testo in ingresso ma vorrei cercare di dividere i dati e togliere i ; presenti..

    dall'echo mi esce:
    AEM.MI;1,71;5/19/2006;17:28;+0,012;1,695;1,72;1,69;4889981

  2. #12

    Puoi ........

    Ciao.
    Usare explode(";",$string);
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #13

    Se può servirti .....

    Non so se ti possa interessare ma
    cq te la posto:
    fscanf
    Nota: Nelle versioni di PHP precedenti alla 4.3.0, il numero massimo di caratteri letti da un file era di 512 (o fino al primo \n, dipende da quale si incontra prima). Dal PHP 4.3.0 si possono esaminare linee di lunghezza arbitraria.
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  4. #14
    $array = file($_SERVER['DOCUMENT_ROOT']."file.csv");

    foreach($array as $rows)
    {
    list($title_p,$description_p)=explode(";",$rows);
    $query = "INSERT INTO post (post_title,post_desc) VALUES ('".$title_p."','".$description_p."')";
    $res = mysql_query($query,$conn);
    mysql_close($conn);
    }

    su questa parte di codice che mi avevi consigliato devo apportare qualche modifica..siccome ci sono campi della stringa che nn uso.

  5. #15

    recuperi

    Ciao.
    Tutti i valori con list e
    nell'insert usi quelli che vuoi
    Stammi bene.
    Mi intriga il giochino !
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  6. #16

    Guarda un po cosa ho trovato ..........

    Ciao.
    Ero a farmi un giretto
    et voilà :
    <?php
    // uncomment this to see plaintext output in your browser
    // header("Content-Type: text/plain");
    // include the ADODB library
    include("adodb.inc.php");
    // create an object instance
    // configure library for a MySQL connection
    $db = NewADOConnection("mysql");
    // open connection to database
    $db->Connect("localhost", "john", "doe", "db278") or die("Unable to
    connect!");
    // prepare query
    $query = $db->Prepare("INSERT INTO library (title, author) VALUES (?,
    ?)");
    // read title-author list in from CSV file
    $data = file("list.txt");
    // iterate through each line in file
    foreach ($data as $l)
    {
    // split on comma
    $arr = explode(";", $l);
    // insert values into prepared query
    $result = $db->Execute($query, array($arr[0], $arr[1])) or
    die("Error in
    query: $query. " . $db->ErrorMsg());
    }
    // clean up
    $db->Close;
    ?>
    Mi pare che usando le adoDB la
    metà del lavoro è fatto !
    Stammi bene.
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  7. #17
    grazie provo ora..
    se ti piace mi potresti aiutare, visto che sembri molto afferato nel php.
    Fammi sapere.

  8. #18

  9. #19

    why not ......

    Ciao.
    In my spare time
    Stammi bene.
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.