Discussion:
php unix filter?
Peter Weil
2008-03-26 17:38:35 UTC
Permalink
We have a php script on a server that has been used to process a
particular type of text file we receive and prepare it for the web. It
has always been run by pasting the text into a web form and clicking
submit.

What would it take to turn this script into a local BBEdit Unix
filter? In particular, what variable do I need to use for content of
the file to be filtered?

(to replace the current

$content =$_POST["wireText"];

)?


Thanks, Peter

--
Peter Weil, Web Developer
University Communications
University of Wisconsin-Madison
Phone: 608-262-6538
Email: ***@wisc.edu
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Jim Correia
2008-03-26 17:44:48 UTC
Permalink
Post by Peter Weil
We have a php script on a server that has been used to process a
particular type of text file we receive and prepare it for the web.
It has always been run by pasting the text into a web form and
clicking submit.
What would it take to turn this script into a local BBEdit Unix
filter? In particular, what variable do I need to use for content of
the file to be filtered?
(to replace the current
$content =$_POST["wireText"];
The content to process is passed to you via a temp file in ARGV.

Jim
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Dennis
2008-03-26 17:46:04 UTC
Permalink
Post by Peter Weil
What would it take to turn this script into a local BBEdit Unix
filter? In particular, what variable do I need to use for content of
the file to be filtered?
BBEdit Unix Filters place the selected text in a temp file and pass
the path of the temp file in $argv[1]. You can use PHP's "file"
function to read the file into an array, one line per element:

----------

#!/usr/bin/php
<?php
$inputArray = file ($argv[1]);
$i = 0;
foreach ($inputArray as $line)
{
$i++;
}
$output = "Number of lines: " . $i . "\n";
?>

----------

Hope this helps,
Dennis
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Carlton Gibson
2008-03-26 18:16:40 UTC
Permalink
Post by Dennis
Post by Peter Weil
What would it take to turn this script into a local BBEdit Unix
filter? In particular, what variable do I need to use for content
of the file to be filtered?
BBEdit Unix Filters place the selected text in a temp file and pass
the path of the temp file in $argv[1]. You can use PHP's "file"
file_get_contents() returns the whole file as a string, which would
be more like the value returned from a single form field via $_POST...
Post by Dennis
----------
#!/usr/bin/php
<?php
$inputArray = file ($argv[1]);
$i = 0;
foreach ($inputArray as $line)
{
$i++;
}
$output = "Number of lines: " . $i . "\n";
?>
----------
Hope this helps,
Dennis
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Peter Weil
2008-03-26 18:33:05 UTC
Permalink
Like this?:

$content = file_get_contents($argv[1]);

[.....]

echo $content;

This would be even simpler, although the array Dennis suggested could
be very useful as well.
- Peter
Post by Carlton Gibson
Post by Dennis
Post by Peter Weil
What would it take to turn this script into a local BBEdit Unix
filter? In particular, what variable do I need to use for content
of the file to be filtered?
BBEdit Unix Filters place the selected text in a temp file and pass
the path of the temp file in $argv[1]. You can use PHP's "file"
file_get_contents() returns the whole file as a string, which would
be more like the value returned from a single form field via $_POST...
Post by Dennis
----------
#!/usr/bin/php
<?php
$inputArray = file ($argv[1]);
$i = 0;
foreach ($inputArray as $line)
{
$i++;
}
$output = "Number of lines: " . $i . "\n";
?>
----------
Hope this helps,
Dennis
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
--
Peter Weil, Web Developer
University Communications
University of Wisconsin-Madison
Phone: 608-262-6538
Email: ***@wisc.edu
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Dennis
2008-03-26 18:42:42 UTC
Permalink
Post by Carlton Gibson
file_get_contents() returns the whole file as a string, which would
be more like the value returned from a single form field via $_POST...
Yea, Carlton is right, file_get_contents() is probably a better
choice. I just threw that example together without thinking.

-Dennis
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Peter Weil
2008-03-26 18:26:43 UTC
Permalink
Wonderful! I've been wanting to convert this darned script for two
years, so I'm glad I finally asked!

After setting $inputArray as Dennis indicated, all I had to do was
change my main content variable to:

$content = implode("", $inputArray);

and make a few other minor changes (no more need to write to a new
file, etc.), and the filter was good to go.

Thank you both!

- Peter
Post by Dennis
Post by Peter Weil
What would it take to turn this script into a local BBEdit Unix
filter? In particular, what variable do I need to use for content
of the file to be filtered?
BBEdit Unix Filters place the selected text in a temp file and pass
the path of the temp file in $argv[1]. You can use PHP's "file"
----------
#!/usr/bin/php
<?php
$inputArray = file ($argv[1]);
$i = 0;
foreach ($inputArray as $line)
{
$i++;
}
$output = "Number of lines: " . $i . "\n";
?>
----------
Hope this helps,
Dennis
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
--
Peter Weil, Web Developer
University Communications
University of Wisconsin-Madison
Phone: 608-262-6538
Email: ***@wisc.edu
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Loading...