Recent Posts
Bash | 11 sec ago
None | 15 sec ago
None | 29 sec ago
Prolog | 32 sec ago
C# | 38 sec ago
None | 47 sec ago
None | 1 min ago
MySQL | 1 min ago
None | 1 min ago
PHP | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
By sbutler on the 21st of Jan 2009 03:47:14 PM
Download |
Raw |
Embed |
Report
#!/usr/bin/perl -w
use strict;
use DBI;
use HTML::Parser;
my $dbh = DBI->connect( 'DBI:mysql:database=mydb;host=myhost.example.org', 'myuser', 'mypass', { RaiseError => 1 } )
|| die "Cannot connect to database: $!";
my $sth_update = $dbh->prepare( 'UPDATE `mytable` SET `body` = ? WHERE `id` = ?' );
my $sth_select = $dbh->prepare( 'SELECT `id`, `body` FROM `mytable`' );
my ($id, $body);
$sth_select->execute;
$sth_select->bind_columns( \$id, \$body );
while ($sth_select->fetch) {
my $tree = HTML::TreeBuilder->new;
$tree->parse( $body );
$tree->eof;
$tree = $tree->elementify;
# skip if this already has a src PARAM
next if $tree->look_down( '_tag' => 'param', 'name' => 'src' );
my $embed = $tree->look_down( '_tag' => 'embed' );
next unless $embed;
my $param = HTML::Element->new( 'param', 'name' => 'src', 'value' => $embed->attr( 'src' ) );
$tree->unshift_content( $param );
$sth_update->execute( $tree->as_HTML, $id );
}
Submit a correction or amendment below.
[ previous version ] | [ difference ] | Make A New Post