PHP 操作 MACOS 剪下板。當然這不可能是 B/S 模式那種,操作用戶端代理(瀏覽器所在系統)的剪下板。B/S結構我們只能使用 JAVASCRIPT 或 FLASH去操作,對於PHP來講只能操作服務端。
這裡將講的是通過調用系統 MACOS 下的 pbcopy、pbpaste 實現操作剪下板。
pbcopy takes the standard input and places it in the specified pasteboard. If no pasteboard is specified, the general pasteboard will be used by default. The input is
placed in the pasteboard as plain text data unless it begins with the Encapsulated PostScript (EPS) file header or the Rich Text Format (RTF) file header, in which case
it is placed in the pasteboard as one of those data types.
pbpaste removes the data from the pasteboard and writes it to the standard output. It normally looks first for plain text data in the pasteboard and writes that to the
standard output; if no plain text data is in the pasteboard it looks for Encapsulated PostScript; if no EPS is present it looks for Rich Text. If none of those types
is present in the pasteboard, pbpaste produces no output.
來看下簡單的使用範例,使用 exec 函數是不是很簡單?呵呵!
/**
* 讀取剪下板內容
*/
exec('pbpaste', $output, $return);
var_dump($output, $return);
/**
* 寫內容(go to clipboard)到剪下板
*/
exec('echo go to clipboard pbcopy', $output, $return);
var_dump($output, $return);