php 使用系统剪切板pbcopy and pbpaste
4 PHP doesn't provide system clipboard api, but we can use php's proc_fopen to call shell command pbcopy on MAC OS X to retrieve this function: echo copy2clipboard('string'); function copy2clipboard($string){ $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file", "a.txt", "a") // stderr is a file to write to ); $process = proc_open('pbcopy', $descriptorspec, $pipes); if (is_resource($process)) { fwrite($pipes[0], $string); fclose($pipes[0]); fclose($pipes[1]); $return_value = proc_close($process); return $return_value; } }
上面的可以修改为:
function copy2clipboard($string){ $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w"), // stderr is a file to write to ); $process = proc_open('pbcopy', $descriptorspec, $pipes); if (is_resource($process)) { fwrite($pipes[0], $string); fclose($pipes[0]); fclose($pipes[1]); $return_value = proc_close($process); return $return_value; } }
2、
浙公网安备 33010602011771号