NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
HOWTO: Use a php script for my editing
Site Admin

Joined: 13 Jul 2003
Posts: 8328
Reply with quote
HOWTO: Use a php script for my editing

Quote:
I want to pass the text that is selected in my editor to a php script, make modifications to the text and then return it back to the editor. So far I know how to run a php script externally from the customizations setting but I don't know how to pass the text in the editor to that script.


Well, you'd follow the instructions below:
1. Create a customization entry (Tools > Settings > Tools > Integration > Add Menu)
2. Set Execute With -> Shell
3. Command line should be
@PHP@ -q "full_path_to_my_script\myscript.php"
if your script is php5, please use @PHP5@ instead of @PHP@ or have .php associated with php5.
4. Other settings:
-check "Show this command in File Bar popup
-check "Work with editor"
-check "Take input from..."
-check "Selected text"
-check "Return results to the editor"
The other settings can be left by default or you can set them according to your needs.

5. your script should read input stream for processing and echo results back, for example:

Code:
<?php

$f = fopen("php://stdin", "r");
$s = fread($f, 100000); // should be big enough
fclose($f);
echo "\"" . $s . "\"";

?>


Please note, that input streeam will be ended with "\n" (line feed), regardless you selected a single char or whole the line.

Very useful scripts integrated this way can be found there:
http://forum.nusphere.com/some-useful-scripts-for-phped-t1989.html
http://forum.nusphere.com/script-to-automate-writing-of-set-get-functions-oop-phpdoc-t3192.html
View user's profileFind all posts by dmitriSend private messageVisit poster's website
HOWTO: Use a php script for my editing
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic