Can PHP copy data to windows clipboard?

As title.

If possible it would only be if it is running on a Windows machine. Easier way would be to create temporary files or copy the information into a session variable.

Yes and no … yes because everything it’s possible if you are writing the text into a file and call a program made in C++ with a system()… you could make it be working!
And it’s no … because in pure PHP there are no such functions…

just use javascript.

here u have a nice script for copying for database looping data!
make a loop and output the div or span or table or whatever u want that have an id :smiley:
then make a button into that loop too where u add onclick event like

onClick='clipboard(".$row[1].")'

so the number outputed for every looping element is his id…
in this case the id is copytext so u insert this name to your loop id…


<div id='copytext".$row[1]."'>

then u use this script…


function ClipBoard(num) {
obj = document.getElementById('copytext'+num);
holdtext.innerText = obj.innerText;
therange = holdtext.createTextRange();
therange.execCommand("RemoveFormat"); // this line here is if u wont copy tags into the element id
therange.execCommand("Copy");
}

so u have copied the text into a loop with certain id :smiley:
cheers :slight_smile:

note: it wont work in firefox… :frowning: only in ie :frowning:

Agreed. In fact, I have some code that I found that works like a charm.

The following code goes inside the </head> tag:

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original:  Russ (NewXS3@aol.com) -->
<!-- Web Site:  http://dblast.cjb.net -->

<!-- Begin
function copyit(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
therange=tempval.createTextRange()
therange.execCommand("Copy")
}
//  End -->
</script>

Here’s how it’s used:

<form name="aspinc">
<pre>
<div align="center">
<input onclick="copyit('aspinc.select1')" type="button" value="Highlight All" name="cpy">
<p>
<textarea class="codebox-sm" name="select1">
Text you want to highlight goes here.
</textarea>
</p>
</pre>
</div>
</form>