Hi Matt,

@ 12:31:35 AM on 5/21/2001, Matt Broughton wrote:

> I'm having some difficulty porting this code from perl to php...can
> anyone give me a hand?

Briefly..

--(snip)--
> #!/usr/bin/perl
> # Quick and dirty Yahoo movie showtimes grabber

> use LWP::Simple;
> my $content =
> get("http://movies.yahoo.com/showtimes/showtimes.html?z=florence%2C+sc&r=sim
> ");

Use fopen() function.

http://www.php.net/manual/en/function.fopen.php


> my $text = '';
> if ($content) {
>         $content =~ s{.*<!-- movies module -->(.*)<!-- /movies
> module -->>.*}{$1}gism;

http://www.php.net/manual/en/ref.pcre.php


>         my @lines = split(/\n/, $content);

Use explode() function.

http://www.php.net/manual/en/function.explode.php


>         my $act = '';
>         foreach (@lines) {

http://www.php.net/manual/en/control-structures.foreach.php

Slightly different foreach syntax.


>                 next if m{^</{0,1}(table|tr|td)};
>                 next unless ($act || /<!-- theater -->/);
>                 if (/<!-- theater -->/) {

Could use switch() here. Also see perl compatible regular expressions
manual link above. Same thing for the string replaces below.

>                         print "\n";
>                         $act = 'theater';
>                         next;
>                 }
>                 elsif (/<!-- .*? movie -->/) {
>                         $act = 'movie';
>                         next;
>                 }
>                 elsif (/<!-- show info -->/) {
>                         $act = 'info';
>                         next;
>                 }
>                 elsif (/more theaters/i) {
>                         $act = 'done';
>                         last;
>                 }

>                 # Strip font tags
>                 s{</{0,1}font.*?>}{}gi;
>                 # Strip HR's
>                 s{<hr>}{}gi;
>                 # Strip non-breaking spaces
>                 s{(&nbsp;)+}{&nbsp;}gi;
>                 s{<p>}{<BR>}gi;

Use strip_tags() function.

http://www.php.net/manual/en/function.strip-tags.php

Also:

http://www.php.net/manual/en/function.htmlspecialchars.php
http://www.php.net/manual/en/function.htmlentities.php


>                 if ($act eq 'theater') {

>                         # Remove links to Yahoo theater stuff
>                         s{<a.*?>(.*?)</a>}{$1}gi;

>                         # Remove Map It link in favor of a linebreak
>                         s{map it}{<BR>}i;

>                                     # Small-italicize anything that's not the 
>theater's name
>                         s{^(.*)$}{<SMALL><I>$1</I></SMALL>} unless m{<B>}i;
>                 }
>                 elsif ($act eq 'movie') {
>                         s{<a href="(.*?)">}{<a
> href="http://movies.yahoo.com$1";>}gi;
>                 }

>                 $text .= "$_ \n";
>         }
> }
> else {
>         $text .= '<P>Movie information is unavailable at this time.';
> }

> print $text;


-Brian
--
 PGP is spoken here: 0xE4D0C7C8
 Please, DO NOT carbon copy me on list replies.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to