|
użytkowników online: 51
|
OPINIE UŻYTKOWNIKÓW
|
Gratulacje i dzięki! Trafiłem tu przypadkiem poszukując informacji na temat php+mysql. Wiele polskich stron powiela identyczne przykłady, klonuje te same kursy i lekcje... ten serwis okazał sie inny. Zasada "problem - rozwiazanie - wyjaśnienie" zdaje egzamin - zapewnia jasną, jednoznaczną i pewną pomoc w konkretnym przypadku. Porady są warte swojej ceny, przede wszystkim ze względu na przyjazną (także dla początkujących) formę i treść oraz bogate i stale powiększane zasoby. Polecam i pozdrawiam!
Kamil Dmowski
Polski Czerwony Krzyż
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
fwrite (PHP 3, PHP 4, PHP 5) fwrite -- Zapis pliku binarnie bezpieczny Opisint fwrite ( resource uchwyt, string łańcuch [, int długość] )
fwrite() zapisuje treść
łańcuch do strumienia pliku wskazanego przez
uchwyt. Jeśli argument długość
został podany, zapis zatrzymywany jest po zapisaniu
długość bajtów lub łańcuch
skończy się, cokolwiek nastąpi szybciej.
fwrite() zwraca liczbę zapisanych bajtów,
lub FALSE w przypadku błędu.
Zauważ, że jeśli argument długość zosta podany,
to konfiguracja magic_quotes_runtime
zostaje zignorowana i żadne slashe nie zostaną usunięte z
łańcucha.
Notatka:
W systemach, które rozróżniają pliki na binarne i tekstowe
(np. Windows) plik musi zostać otworzony z 'b' włączonym do
parametru tryb funkcji fopen().
Przykład 1. Prosty przykład fwrite |
<?php
$nazwapliku = 'test.txt';
$trochetresci = "Dodaj to do pliku\n";
if (is_writable($nazwapliku)) {
if (!$uchwyt = fopen($nazwapliku, 'a')) {
echo "Nie mogę otworzyć pliku ($nazwapliku)";
exit;
}
if (fwrite($uchwyt, $trochetresci) === FALSE) {
echo "Nie mogę zapisać do pliku ($nazwapliku)";
exit;
}
echo "Sukces, zapisano ($trochetresci) do pliku ($nazwapliku)";
fclose($uchwyt);
} else {
echo "Plik $nazwapliku nie jest zapisywalny";
}
?>
|
|
Patrz także: fread(),
fopen(),
fsockopen(),
popen() i
file_put_contents().
User Contributed Noteswizdkid at wizdkid dot com
02-Jan-2006 05:56
> In PHP 4.3.7 fwrite returns 0 rather than false on
> failure.
Actually it can return any of these:
-NULL,
-0,
-FALSE
This means instead of writing the example shown:
<?php
if (fwrite($handle, $somecontent) === FALSE) { }
?>
You could write something shorter like:
<?php
if ( !fwrite($handle, $somecontent) ) { }
?>
It is a better coding to define the ! (is not) before the arguments. But both work fine.
aaron-php at oakadaptive dot com
14-Oct-2005 02:01
chill at cuna dot org wrote:
> In PHP 4.3.7 fwrite returns 0 rather than false on
> failure.
This is true (under certain circumstances) in (at least) PHP
4 and 5. I filed it as a bug (see [1]) but it's the
intended behavior -- writing less than the requested number
of bytes is not considered an error.
This means that you should only consider an fwrite
successful if its return value is the same as the length of
the string you passed to it. (fwrite fails in this
particular way if the filesystem is full, or if the file was
opened in read-only mode, and probably in yet other
situations.)
fwrite does return false (and trigger a warning) in certain
cases; e.g., when it's passed an invalid file handle.
[1] <http://bugs.php.net/bug.php?id=34860>
--
Aaron
bahatest at ifrance doc com
23-Jul-2005 11:40
[Editor's Note: No, you only need to use this if you want a BOM (Byte order mark) added to the document - most people do not.]
if you have to write a file in UTF-8 format, you have to add an header to the file like this :
<?php
$f=fopen("test.txt", "wb");
$text=utf8_encode("
|