Current location: Hot Scripts Forums » Programming Languages » Perl » Could anyone please convert this perl code into PHP


Could anyone please convert this perl code into PHP

Reply
  #1 (permalink)  
Old 09-28-07, 07:17 PM
mynk.sharma mynk.sharma is offline
Newbie Coder
 
Join Date: Sep 2007
Location: India
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Could anyone please convert this perl code into PHP

hi I'm PHP programmer. I don't know anything about Perl, I want this code in PHP.
Could anyone help me. its really very urgent.

Thanks in Advance

Perl Code:
  1. #!/usr/bin/perl
  2. #
  3.  
  4. =head1 NAME
  5.  
  6. loadniabarticles.pl - Website Database Load NIAB Articles Table Script
  7.  
  8. =cut
  9.  
  10. use lib (qw(/home/bignm2/perl));
  11.  
  12. {
  13.    package Website::LoadNIABArticles;
  14.  
  15.    use Website;
  16.    use Carp;
  17.  
  18.    if (my $ws = new Website) {
  19.       open SESSION, $ws->{'config'}{'path_of_sessions_directory'} .
  20. '/sessions';
  21.       eval { flock(SESSION, LOCK_EX) };
  22.       eval { setpriority(0, $$, 20); };
  23.       opendir DIR, "." or die "Cannot open current directory: $!";
  24.       my @files = grep { m"\.txt$"o } readdir DIR;
  25.       closedir DIR;
  26.       die "Exiting - No Files Found." unless @files;
  27.       $ws->connectdb();
  28.       my $type = 'nichesinabox';
  29.       my $status = 'loaded';
  30.       my $table = 'articles';
  31.       my $where = '';
  32.       my $cols = 'MAX(id) + 1 AS nextid';
  33.       my $attrs = { 'nocommas' => 1 };
  34.       my $nextidref = $ws->selectdb($table, $where, $cols, $attrs);
  35.       $nextid = $nextidref->[0]{'nextid'} || 1;
  36.       foreach my $file (@files) {
  37.          print $file, "\n";
  38.          my ($keyphrase) = $file =~ m"^([-\w\s]+)\.txt"o;
  39.          $keyphrase =~ s"[-_]" "go;
  40.          $keyphrase = $ws->trim(lc($keyphrase));
  41.          my $author = 'tomstraub';
  42.          my $title = '';
  43.          open FILE, $file or die "Cannot open file '$file': $!";
  44.          my $content = '';
  45.          for (my $counter = 1; my $line = <FILE>; $counter++) {
  46.             chomp $line;
  47.             $title = $ws->trim($line) if $counter == 1;
  48.             next if $line =~ m"^\s*$"o or $counter <= 3;
  49.             $line =~ s"\r""go;
  50.             $line =~ s"^\s*""o;
  51.             $line =~ s"\s*$""o;
  52.             $line =~ s/\x{82}/,/go;
  53.             $line =~ s/\x{85}/.../go;
  54.             $line =~ s/\x{88}/^/go;
  55.             $line =~ s/\x{8B}/</go;
  56.             $line =~ s/\x{91}/'/go;
  57.             $line =~ s/\x{92}/'/go;
  58.             $line =~ s/\x{93}/"/go;
  59.             $line =~ s/\x{94}/"/go;
  60.             $line =~ s/\x{96}/-/go;
  61.             $line =~ s/\x{97}/-/go;
  62.             $line =~ s/\x{98}/~/go;
  63.             $line =~ s/\x{9B}/>/go;
  64.             $line =~ s/\x{A6}/|/go;
  65.             $line =~ s/\x{A9}/(c)/go;
  66.             $line =~ s/\x{AB}/<</go;
  67.             $line =~ s/\x{AD}/-/go;
  68.             $line =~ s/\x{AE}/(R)/go;
  69.             $line =~ s/\x{B4}/'/go;
  70.             $line =~ s/\x{BB}/>>/go;
  71.             $line =~ s/\x{BC}/1\/4/go;
  72.             $line =~ s/\x{BD}/1\/2/go;
  73.             $line =~ s/\x{BE}/3\/4/go;
  74.             $line =~ s/\x{D7}/x/go;
  75.             $line =~ s/\x{F7}/\//go;
  76.             $content .= "$line\n";
  77.          }
  78.          close FILE;
  79.          my $colsref = {
  80.             'id' => $nextid++,
  81.             'keyphrase' => $keyphrase,
  82.             'title' => $title,
  83.             'content' => $content,
  84.             'type' => $type,
  85.             'status' => $status,
  86.             'author' => $author,
  87.          };
  88.          my @errors = $ws->insertdb($table, $colsref);
  89.          die $errors[0] if @errors;
  90.       }
  91.       $ws->disconnectdb();
  92.       close SESSION;
  93.       exit;
  94.    }
  95.    else {
  96.       die $!;
  97.    }
  98. }

Last edited by UnrealEd; 10-01-07 at 03:57 AM. Reason: please use the correct syntax highlighter when posting Perl code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-30-07, 11:34 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
This would be a little complicated to convert directly, since it uses a specific module (package Website::LoadNIABArticles) which probably contains some additional code and functions.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-02-07, 12:38 AM
Drunken Perl Coder Drunken Perl Coder is offline
Wannabe Coder
 
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
I think that is the LoadNIABArticles module:

package Website::LoadNIABArticles;

but it does use another module:

use Website;

not that I have any clue how to write that in PHP though.
__________________
Mods: Please do not edit my posts to add syntax highlighting. Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP inside JavaScript? pikaz JavaScript 20 07-10-10 01:55 AM
Urgent need to convert small snippet from perl to asp.net (asp) hejlsberg ASP.NET 3 04-21-06 07:56 AM
Perl code : print "." x 20; - How to do it with PHP ? kevin PHP 2 07-04-03 05:29 AM


All times are GMT -5. The time now is 01:40 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.