in reply to Grabbing url from iframe

Which one is it? Do you want to change the height and width, or do you want to extract* the URL of the frame's content? Those aren't remotely similar in effect.

Furthermore, you didn't given any indication of what problem you are facing. How can we help you with your problem if you don't tell us what it is?

* — You said "strip", but based on your last post, you mean "extract" when you say "strip". To strip is to remove.

Replies are listed 'Best First'.
Re^2: Grabbing url from iframe
by htmanning (Friar) on Feb 12, 2011 at 04:00 UTC
    Yes, sorry I guess strip isn't the right term. I'd prefer to reduce the width and height but that seems like more of a hassle so I thought I'd simply show a graphic in place of the video on the mobile site, and provide a link to the YouTube version. Therefore, I need to be able to strip out the url. I tried to adapt this code, but I'm not having much luck.
    my $video = $video; my @parts = split /\<iframe(.+)src=\"/http(.+)/\"(.+)\<\/iframe\>/, $v +ideo; (my $video )= $parts[-2] =~ m/(\d+)/;
    This may not be the right way to do this at all but... Thanks.

      The approach is fundamentally bad. You're using split, but you don't have a separated list of things to split on.

      Either option you choose, you need to

      1. Parse the HTML
      2. Locate the elements
      3. Modify the elements
      4. Regenerate the HTML

      In this case, that can all be done by one substitution.

      s/ (<iframe [ ]title="YouTube[ ]video[ ]player" [ ]width=")([0-9]+)(" [ ]height=")([0-9]+)(" ) / $1 . "320" . $3 . ( (320/$2)*$4 ) . $5 /xeg
        Thanks for this. Here's what I have:
        $video =~ s/ (<iframe [ ]title="YouTube[ ]video[ ]player" [ ]width=")([0-9]+)(" [ ]height=")([0-9]+)(" ) / $1 . "320" . $3 . ( (320/$2)*$4 ) . $5 /xeg;
        But it's returning this error:
        Scalar found where operator expected at mobile.pl line 296, near "$1 . + "320" . $3 . ( (320/$2" (Might be a runaway multi-line // string starting on line 289) (Missing operator before $2?) syntax error at mobile.pl line 296, near "$1 . "320" . $3 . ( (320/$2"
        Am I missing something?