Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Zapisivanje u *.txt

[es] :: PHP :: Zapisivanje u *.txt

[ Pregleda: 2779 | Odgovora: 8 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

blzz
mostar

Član broj: 36745
Poruke: 110
212.39.111.*

Sajt: www.chunoslav.tk


Profil

icon Zapisivanje u *.txt17.02.2005. u 21:54 - pre 233 meseci
E vidite ovo iz flasha sam poslao varijable koje se zovu " ime " i " poruka ".
Ima txt file koji se zove ShoutBox.txt i u sebi sadrži samo title= .
Možete li mi molim Vas napisati neki kod da php skripta upiše u *.txt file poruku koja sadrži varijable dobivene iz flasha. Ovakav bi trebao biti format poruke:

<b>$ime</b><br><b>$poruka</b>

Molim vas pomozite...
Ali PhP mora ispunjavati ovaj uvjet, da se svaki put kada se php upiše novu poruku, da je upiše ispred title=. evo primjera: kako bi trebalo biti:

title=<b>Marko</b><br><b>hihi</b><br><b>mirko</b><br><b>haha</b>

E sada imam ja jedan php kod, ali on upiuje svaku poruku ispred title= pa flash nemože iscitati novu poruku.
Code:
<?php
// If you are using an old version of php, remove the next set of lines.
// or use $HTTP_POST_VARS["..."] instead.
$Submit     = $_POST["Submit"];
$Name         = $_POST["Name"];
$Email         = $_POST["Email"];
$Website     = $_POST["Website"];
$Comments     = $_POST["Comments"];
$NumLow     = $_REQUEST["NumLow"];
$NumHigh     = $_REQUEST["NumHigh"];

// Replace special characters - you can remove the next 5 lines if wanted.
$Name         = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
$Email         = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
$Comments    = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);
$Website     = eregi_replace("http://", "", $Website);
$Website     = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);

// Remove slashes.
$Name         = stripslashes($Name);
$Email         = stripslashes($Email);
$Website     = stripslashes($Website);
$Comments     = stripslashes($Comments);

// ########## Reading and Writing the new data to the GuestBook Database 
if ($Submit == "Yes") {
// Next line tells the script which Text file to open.
    $filename     = "GuestBook.txt";

// Opens up the file declared above for reading 

    $fp         = fopen( $filename,"r"); 
    $OldData     = fread($fp, 80000); 
    fclose( $fp ); 

// Gets the current Date of when the entry was submitted
    $Today         = (date ("l dS of F Y ( h:i:s A )",time()));

// Puts the recently added data into html format that can be read into the Flash Movie.
// You can change this up and add additional html formating to this area.  For a complete listing of all html tags
// you can use in flash - visit: http://www.macromedia.com/support/flash/ts/documents/htmltext.htm

    $Input = "Ime<b>$Name</b>= <b>$Name</b><br>Link<b>$Name</b>= <b><u><a href=\"$Website\" target=\"_blank\">$Website</a></u></b>";

/* This Line adds the '&GuestBook=' part to the front of the data that is stored in the text file.  This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file  */

    $New = "$Input$OldData";

// Opens and writes the file.

    $fp = fopen( $filename,"w"); 
    if(!$fp) die("&GuestBook=cannot write $filename ......&");
    fwrite($fp, $New, 800000); 
    fclose( $fp ); 
}

// ###################################################################################
// ######### Formatting and Printing the Data from the Guestbook to the Flash Movie ##



// Next line tells the script which Text file to open.
    $filename = "GuestBook.txt";

// Opens up the file declared above for reading 

    $fp     = fopen( $filename,"r"); 
    $Data     = fread($fp, 800000); 
    fclose( $fp );

// Splits the Old data into an array anytime it finds the pattern .:::.
    $DataArray = split ("Title=", $Data);

// Counts the Number of entries in the GuestBook
    $NumEntries = count($DataArray) - 1;

    print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
    for ($n = $NumLow; $n < $NumHigh; $n++) {
    print $DataArray[$n];
        if (!$DataArray[$n]) {
            Print "<br><br><b>Nema vishe nichega</b>";
        exit
        }
    }
?>


E to je PhP kod koji ja imam. On kada upiše poruku tekst će izgledati ovako:
<b>Marko</b><br><b>hihi</b>title=<b>mirko</b><br><b>haha</b>

A meni treba ovako izgledati kada se upiše nova vijest:
title=<b>Marko</b><br><b>hihi</b><br><b>mirko</b><br><b>haha</b>

Ako je ovo nemoguće može li se uraditi nešto ovako da poruka bude ovakvog tipa:
title= <b>$ime</b><br><b>$poruka</b>, ali da se svaki put prije nego php upiše novu poruku, php izbriše title= koji već postoji u tekstu.

Aje nadam se da ste me shvatili.

Evo sada skraćeno možete li napraviti nekakvu php skriptu da upisuje poruku (tipa <b>$ime</b><br><b>$poruka</b> ) u txt file koji već sadrži title=, ito tako da se svaka poruka nađe iza title= pa da to izgleda ovako title=<b>Marko</b><br><b>hihi</b><br><b>mirko</b><br><b>haha</b>, ili da napravite da poruka izgleda ovako " title= <b>$ime</b><br><b>$poruka</b> ", ali da se title= koji već postoji u tekstu izbriše prije upisivanja nove poruke u *.txt
 
Odgovor na temu

dado_k
Varaždin

Član broj: 57122
Poruke: 300
*.alcyonis.fr.

ICQ: 326865106
Sajt: radim baš novi sajt u ph..


Profil

icon Re: Zapisivanje u *.txt01.08.2005. u 21:29 - pre 227 meseci
simple as that
Code:

<?php
// If you are using an old version of php, remove the next set of lines.
// or use $HTTP_POST_VARS["..."] instead.
$Submit     = $_POST["Submit"];
$Name         = $_POST["Name"];
$Email         = $_POST["Email"];
$Website     = $_POST["Website"];
$Comments     = $_POST["Comments"];
$NumLow     = $_REQUEST["NumLow"];
$NumHigh     = $_REQUEST["NumHigh"];

// Replace special characters - you can remove the next 5 lines if wanted.
$Name         = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
$Email         = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
$Comments    = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);
$Website     = eregi_replace("http://", "", $Website);
$Website     = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);

// Remove slashes.
$Name         = stripslashes($Name);
$Email         = stripslashes($Email);
$Website     = stripslashes($Website);
$Comments     = stripslashes($Comments);

// ########## Reading and Writing the new data to the GuestBook Database 
if ($Submit == "Yes") {
// Next line tells the script which Text file to open.
    $filename     = "GuestBook.txt";

// Opens up the file declared above for reading 

    $fp         = fopen( $filename,"r"); 
    $OldData     = fread($fp, 80000); 
    fclose( $fp ); 

// Gets the current Date of when the entry was submitted
    $Today         = (date ("l dS of F Y ( h:i:s A )",time()));

// Puts the recently added data into html format that can be read into the Flash Movie.
// You can change this up and add additional html formating to this area.  For a complete listing of all html tags
// you can use in flash - visit: http://www.macromedia.com/support/flash/ts/documents/htmltext.htm

    $Input = "title=Ime<b>$Name</b>= <b>$Name</b><br>Link<b>$Name</b>= <b><u><a href=\"$Website\" target=\"_blank\">$Website</a></u></b>";

/* This Line adds the '&GuestBook=' part to the front of the data that is stored in the text file.  This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file  */

    $New = "$Input$OldData";

// Opens and writes the file.

    $fp = fopen( $filename,"w"); 
    if(!$fp) die("&GuestBook=cannot write $filename ......&");
    fwrite($fp, $New, 800000); 
    fclose( $fp ); 
}

// ###################################################################################
// ######### Formatting and Printing the Data from the Guestbook to the Flash Movie ##



// Next line tells the script which Text file to open.
    $filename = "GuestBook.txt";

// Opens up the file declared above for reading 

    $fp     = fopen( $filename,"r"); 
    $Data     = fread($fp, 800000); 
    fclose( $fp );

// Splits the Old data into an array anytime it finds the pattern .:::.
    $DataArray = split ("Title=", $Data);

// Counts the Number of entries in the GuestBook
    $NumEntries = count($DataArray) - 1;

    print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
    for ($n = $NumLow; $n < $NumHigh; $n++) {
    print $DataArray[$n];
        if (!$DataArray[$n]) {
            Print "<br><br><b>Nema vishe nichega</b>";
        exit
        }
    }
?>
 
Odgovor na temu

101kerber
Zagreb

Član broj: 81061
Poruke: 47
*.adsl.net.t-com.hr.



Profil

icon Re: Zapisivanje u *.txt01.03.2007. u 22:39 - pre 208 meseci
Mene zanima kako da upišem npr. 3 nova reda u .txt file ali na početak tog fajla, a bez prethodnog učitavanja cijelog teksta iz fajla pa ponovnog upisivanja?
 
Odgovor na temu

101kerber
Zagreb

Član broj: 81061
Poruke: 47
*.adsl.net.t-com.hr.



Profil

icon Re: Zapisivanje u *.txt02.03.2007. u 22:35 - pre 208 meseci
Dali je pitanje toliko jednostavno da nitko ne želi odgovoriti ili se takvo nešto ne može napraviti?

Da budem jasan, želim ubaciti neki tekst na početak .txt fajla. Po mogućnosti bez prethodnog učitavanja ostatka fajla.
 
Odgovor na temu

Jezdimir Lončar
Aka Blazeme
PHP/jQuery Dev, BildStudio
Crna Gora / Pljevlja

Član broj: 74833
Poruke: 674
*.crnagora.net.

Jabber: jezdonet@gmail.com


+4 Profil

icon Re: Zapisivanje u *.txt02.03.2007. u 23:55 - pre 208 meseci
Da bi sprijecio ispis, izbrises taj dio:
Code:

Code:

<?php
// If you are using an old version of php, remove the next set of lines.
// or use $HTTP_POST_VARS["..."] instead.
$Submit     = $_POST["Submit"];
$Name         = $_POST["Name"];
$Email         = $_POST["Email"];
$Website     = $_POST["Website"];
$Comments     = $_POST["Comments"];
$NumLow     = $_REQUEST["NumLow"];
$NumHigh     = $_REQUEST["NumHigh"];

// Replace special characters - you can remove the next 5 lines if wanted.
$Name         = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
$Email         = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
$Comments    = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);
$Website     = eregi_replace("http://", "", $Website);
$Website     = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);

// Remove slashes.
$Name         = stripslashes($Name);
$Email         = stripslashes($Email);
$Website     = stripslashes($Website);
$Comments     = stripslashes($Comments);

// ########## Reading and Writing the new data to the GuestBook Database 
if ($Submit == "Yes") {
// Next line tells the script which Text file to open.
    $filename     = "GuestBook.txt";

// Opens up the file declared above for reading 

    $fp         = fopen( $filename,"r"); 
    $OldData     = fread($fp, 80000); 
    fclose( $fp ); 

// Gets the current Date of when the entry was submitted
    $Today         = (date ("l dS of F Y ( h:i:s A )",time()));

// Puts the recently added data into html format that can be read into the Flash Movie.
// You can change this up and add additional html formating to this area.  For a complete listing of all html tags
// you can use in flash - visit: http://www.macromedia.com/support/flash/ts/documents/htmltext.htm

    $Input = "title=Ime<b>$Name</b>= <b>$Name</b><br>Link<b>$Name</b>= <b><u><a href=\"$Website\" target=\"_blank\">$Website</a></u></b>";

/* This Line adds the '&GuestBook=' part to the front of the data that is stored in the text file.  This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file  */

    $New = "$Input$OldData";

// Opens and writes the file.

    $fp = fopen( $filename,"w"); 
    if(!$fp) die("&GuestBook=cannot write $filename ......&");
    fwrite($fp, $New, 800000); 
    fclose( $fp ); 
}

// ###################################################################################
?>

E da - ja pojma nemam sta ti u stvari hoces.
Tip 1: I za ubuduce - nemoj ocekivati da ti neko pise kod:
Citat:

...
Možete li mi molim Vas napisati neki kod da php ...

Tip 2: Pogledaj malo php man. Bas sam skinuo CHM (extended) i extra je. Pogledaj funkciju fopen,fwrite,fread itd.
“I never think of the future - it comes soon enough.” - Albert Anštajn (Albert Einstein)
 
Odgovor na temu

101kerber
Zagreb

Član broj: 81061
Poruke: 47
*.adsl.net.t-com.hr.



Profil

icon Re: Zapisivanje u *.txt04.03.2007. u 12:34 - pre 208 meseci
Gledao sam po php manualu, za ove fopen i slične već znam, ali me zanimalo dali mogu ikako ubaciti samo liniju ili dvije na početak txt fajla bez da moram učitavati cijeli fajl (što sam na kraju napravio).

Htio sam vidjeti dali postoji brže riješenje od onoga koje sam ja zamislio. Za sada nisam pronašao. Tako da sam prvo učitao sadržaj fajla, ispraznio cijeli fajl, dodao svojih par linija i onda vratio na kraj onaj prijašnji sadržaj fajla. Ali ako fajl postane malo veći tada bi to moglo malo predugo trajati. Iz nekih čudnih razloga ne mogu koristiti bazu.
 
Odgovor na temu

w3bl0rd
Varaždin, Hrvatska

Član broj: 82659
Poruke: 380
*.cmu.carnet.hr.



+26 Profil

icon Re: Zapisivanje u *.txt04.03.2007. u 13:26 - pre 208 meseci
1. otvoriš fajl
2.Pointera staviš na početak
3. zapišeš šta želiš
4. zatvoriš fajl
there's no place like 127.0.0.1
 
Odgovor na temu

101kerber
Zagreb

Član broj: 81061
Poruke: 47
*.adsl.net.t-com.hr.



Profil

icon Re: Zapisivanje u *.txt04.03.2007. u 20:41 - pre 208 meseci
Citat:
w3bl0rd: 1. otvoriš fajl
2.Pointera staviš na početak
3. zapišeš šta želiš
4. zatvoriš fajl


Zar je to moguće sa upisom?

Sada sam isprobao, ako otvorim fajl sa 'w', tada se sav prethodni sadržaj iz fajla izbriše,a ako koristim 'a', tada bez obzira na to gdje postavim pointer, upisani tekst se dodaje na kraj fajla.
Dali si ti isprobao ovu svoju metodu, koje naredbe si onda koristio?

[Ovu poruku je menjao 101kerber dana 04.03.2007. u 21:51 GMT+1]
 
Odgovor na temu

RuleMaker
RuleMaker
Freelancer
Novi Sad

Član broj: 158531
Poruke: 23
*.eunet.yu.

Sajt: www.designfusion.co.cc


Profil

icon Re: Zapisivanje u *.txt02.10.2007. u 21:53 - pre 201 meseci
Čekaj, jel ti hoćeš da dodaješ tekst na početak ili na kraj fajla?
U svakom slučaju pročitaj ovo:
http://www.w3schools.com/php/func_filesystem_fopen.asp
Ako kojim slučajem hoćeš da dodaješ na početak onda bi to morao ovako da uradiš:
1)otvoriš fajl
2)sadržaj staviš u promenljivu
3)dodaš novi tekst u fajl
4)snimiš fajl
5)ponovo ga učitaš sa "a"
6)dodaš vrednost promenljive kojoj si dao vrednost u drugom koraku
7)snimš fajl
8)zatvoriš fajl
Nadam se da će ti ovo pomoći :)
 
Odgovor na temu

[es] :: PHP :: Zapisivanje u *.txt

[ Pregleda: 2779 | Odgovora: 8 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.