0
一些解釋here。這是爲了將任意的javascript代碼轉換成適用於bookmarklets的代碼。這個Perl腳本的PHP等價物是什麼?
#!/usr/bin/env perl
#
# http://daringfireball.net/2007/03/javascript_bookmarklet_builder
# Licence: http://www.opensource.org/licenses/mit-license.php
use strict;
use warnings;
use URI::Escape qw(uri_escape_utf8);
use open IO => ":utf8", # UTF8 by default
":std"; # Apply to STDIN/STDOUT/STDERR
my $src = do { local $/; <> };
# Zap the first line if there's already a bookmarklet comment:
$src =~ s{^// ?javascript:.+\n}{};
my $bookmarklet = $src;
for ($bookmarklet) {
s{^\s*//.+\n}{}gm; # Kill comments.
s{\t}{ }gm; # Tabs to spaces
s{[ ]{2,}}{ }gm; # Space runs to one space
s{^\s+}{}gm; # Kill line-leading whitespace
s{\s+$}{}gm; # Kill line-ending whitespace
s{\n}{}gm; # Kill newlines
}
# Escape single- and double-quotes, spaces, control chars, unicode:
$bookmarklet = "javascript:" .
uri_escape_utf8($bookmarklet, qq('" \x00-\x1f\x7f-\xff));
print "// $bookmarklet\n" . $src;
# Put bookmarklet on clipboard:
`/bin/echo -n '$bookmarklet' | /usr/bin/pbcopy`;
你對此不瞭解麼?你的進度停在哪裏? – Lepidosteus 2011-05-26 12:35:07
你是要求有人爲你重寫這個嗎?也許這是一個更合適的地方:http://www.elance.com/ – 2011-05-26 12:36:34
'for'部分。我知道它正在應用一些正則表達式,但無法弄清它是如何取代事物的。 – 2011-05-26 12:37:54