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...
Learn a little bit about the new Pastebin.com on our help page. hide message
By sbutler on the 21st of Jan 2009 03:47:14 PM Download | Raw | Embed | Report
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4.  
  5. use DBI;
  6. use HTML::Parser;
  7.  
  8. my $dbh = DBI->connect( 'DBI:mysql:database=mydb;host=myhost.example.org', 'myuser', 'mypass', { RaiseError => 1 } )
  9.         || die "Cannot connect to database: $!";
  10.  
  11. my $sth_update = $dbh->prepare( 'UPDATE `mytable` SET `body` = ? WHERE `id` = ?' );
  12. my $sth_select = $dbh->prepare( 'SELECT `id`, `body` FROM `mytable`' );
  13.  
  14. my ($id, $body);
  15.  
  16. $sth_select->execute;
  17. $sth_select->bind_columns( \$id, \$body );
  18. while ($sth_select->fetch) {
  19.         my $tree = HTML::TreeBuilder->new;
  20.  
  21.         $tree->parse( $body );
  22.         $tree->eof;
  23.         $tree = $tree->elementify;
  24.  
  25.         # skip if this already has a src PARAM
  26.         next if $tree->look_down( '_tag' => 'param', 'name' => 'src' );
  27.  
  28.         my $embed = $tree->look_down( '_tag' => 'embed' );
  29.         next unless $embed;
  30.  
  31.         my $param = HTML::Element->new( 'param', 'name' => 'src', 'value' => $embed->attr( 'src' ) );
  32.         $tree->unshift_content( $param );
  33.  
  34.         $sth_update->execute( $tree->as_HTML, $id );
  35. }
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: