Beispiele

Inhaltsverzeichnis

Beispiel #1 Using file_get_contents() to retrieve data from multiple sources

<?php
/* Read local file from /home/bar */
$localfile file_get_contents("/home/bar/foo.txt");

/* Identical to above, explicitly naming FILE scheme */
$localfile file_get_contents("file:///home/bar/foo.txt");

/* Read remote file from www.example.com using HTTP */
$httpfile  file_get_contents("http://www.example.com/foo.txt");

/* Read remote file from www.example.com using HTTPS */
$httpsfile file_get_contents("https://www.example.com/foo.txt");

/* Read remote file from ftp.example.com using FTP */
$ftpfile   file_get_contents("ftp://user:pass@ftp.example.com/foo.txt");

/* Read remote file from ftp.example.com using FTPS */
$ftpsfile  file_get_contents("ftps://user:pass@ftp.example.com/foo.txt");
?>

Beispiel #2 Making a POST request to an https server

<?php
/* Send POST request to https://secure.example.com/form_action.php
* Include form elements named "foo" and "bar" with dummy values
*/

$sock fsockopen("ssl://secure.example.com"443$errno$errstr30);
if (!
$sock) die("$errstr ($errno)\n");

$data "foo=" urlencode("Value for Foo") . "&bar=" urlencode("Value for Bar");

fwrite($sock"POST /form_action.php HTTP/1.0\r\n");
fwrite($sock"Host: secure.example.com\r\n");
fwrite($sock"Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock"Content-length: " strlen($data) . "\r\n");
fwrite($sock"Accept: */*\r\n");
fwrite($sock"\r\n");
fwrite($sock$data);

$headers "";
while (
$str trim(fgets($sock4096)))
$headers .= "$str\n";

echo 
"\n";

$body "";
while (!
feof($sock))
$body .= fgets($sock4096);

fclose($sock);
?>

Beispiel #3 Writing data to a compressed file

<?php
/* Create a compressed file containing an arbitrary string
* File can be read back using compress.zlib stream or just
* decompressed from the command line using 'gzip -d foo-bar.txt.gz'
*/
$fp fopen("compress.zlib://foo-bar.txt.gz""wb");
if (!
$fp) die("Unable to create file.");

fwrite($fp"This is a test.\n");

fclose($fp);
?>

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

AI Nude Tool—Make Deepnude & Deepfake for Free

Ein Thread voller Spam im Board IT-Security, genau mein Humor. :rofl:

Geschrieben von scatello am 05.04.2025 14:48:56
Forum: IT-Security
AI Nude Tool—Make Deepnude & Deepfake for Free

I've always been curious about numerology and your post answered so many questions! Destiny Matrix (https://destiny-matrix.cc/)​ has been my go- ...

Geschrieben von yxchen1994 am 05.04.2025 13:13:14
Forum: IT-Security
AI Nude Tool—Make Deepnude & Deepfake for Free

As a teacher, I use Ghiblify (https://ghiblify.run/) to transform classroom projects into magical scenes. My students are always excited to see th ...

Geschrieben von yxchen1994 am 05.04.2025 13:12:42
Forum: IT-Security
Helfen! Doppelte Bestelleinträge in meiner Verkaufstabelle

I am struggling to start learning about code. I have a background in economics Bendomenech68, ich betreibe Online-Handel seit 2010, und selbst da ...

Geschrieben von MannesHaar am 03.04.2025 16:21:46
Forum: SQL / Datenbanken