ฟังก์ชั่น popen()
ความหมายของฟังก์ชั่นและการใช้งาน
การเปิดไฟล์แบบ pipe โดยจะคืนค่ารหัสประจำไฟล์กลับมา ถ้าไม่สามารถเปิดไฟล์ได้จะคืนค่า false กลับมา ด้วยฟังก์ชั่น popen()
รูปแบบการเขียน (Syntax)
- ตัวแปร command คือคำสั่งของ cmd
resource popen ( string $command , string $mode )
ตัวอย่างที่ 1
<?php
$handle = popen("/bin/ls", "r");
?>
ตัวอย่างที่ 2
<?php
error_reporting(E_ALL);
/* Add redirection so we can get stderr. */
$handle = popen('/path/to/executable 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
?>