Last active
July 30, 2017 16:33
-
-
Save davebarnwell/11c25690972ecc1452a41fde35dd66b2 to your computer and use it in GitHub Desktop.
PHP to copy a string to the mac os x paste board
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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; | |
} | |
} | |
copy2clipboard('The string to copy to the paste board'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment