file_get_contents() in php get content ของเว็บไซต์หรือไฟล์

22 May 2018,
Share: 

file_get_contents() เป็น function ภาษา PHP ใช้สําหรับดึงข้อมูลจากไฟล์ หรือ url มาดูตัวอย่างการใช้งานกันเลยครับ

Example1: ดึงข้อมูลจากไฟล์ demo.txt ขึ้นมาแสดง ไฟล์ demo.txt มีเนื้อหาดังนี้

demo file php.

ไฟล์ index.php มีเนื้อหาดังนี้

<?php
    $homepage = file_get_contents('demo.txt');
    echo $homepage;
?>

Output: แสดงข้อความ “demo file php.” บนหน้าจอ Example2: ดึงข้อมูลจากเว็บ google.com มาแสดงผล

<?php
    $homepage = file_get_contents('http://www.google.com/');
    echo $homepage;
?>

Output: ระบบจะ echo ข้อมูล String html ของเว็บ google.com ออกมาจะได้เป็นหน้าจอนี้

Image

Suggestion blogs

Review ไฟฉาย Olight sMini limited edition

ไฟฉาย Olight sMini limited edition เป็นรุ่นที่มีขนาดเล็ก ใส่แบตเตอรี่ CR123 ยาวเพียง 5.45 ซม มาดูคุณสมบัติกันครับ

Go EP.9 Go Context

สวัสดีครับ ในบทความนี้ก็เป็น EP.9 แล้วนะครับ โดยเนื้อหาจะเป็นเรื่องเกี่ยวกับ Context ในภาษา Go ซึ่งเป็นเรื่องที่เราจะต้องได้เจอเมื่อเราพัฒนาโปรแกรมด้วยภาษา Go ครับสําหรับท่านใดที่ยังไม่ได้อ่าน EP.8 ท่านสามารถกลับไปอ่านก่อนได้นะครับที่นี่ Go EP.8 Go Channel Select Multiple Communication Operationsมาเริ่มเรียนรู้ไปด้วยกันตามหัวข้อด้านล่างเลยครับ

Flutter EP.2.1 Class และ Object ในภาษา Dart

สวัสดีครับ หลังจาก EP.2 เราได้เรียนรู้ Syntax ของภาษา Dart กันไปแล้ว สําหรับ EP นี้ก็จะเป็น เนื้อหาเพิ่มเติมซึ่งจะเกี่ยวข้องกับ Class และ Object ในภาษา Dart


Copyright © 2019 - 2025 thiti.dev |  v1.58.0 |  Privacy policy | 

Build with ❤️ and Astro.

Github profile   Linkedin profile   Instagram   X profile   Nostr   Youtube channel   Telegram   Email contact   วงแหวนเว็บ