file_get_contents help

Discussion in 'PHP' started by dnsman, Feb 15, 2010.

  1. #1
    This: othersite.com <- source:
    <head>
    ......
    </head><body>...

    <script type="text/javascript">
    var so = new SWFObject('../../mediaplayer/mediaplayer.swf','mpl','730','20','9');
    so.addParam('allowfullscreen','true');
    so.addParam('flashvars','height=20&amp;width=730&amp;file=downloadMusic%3Fkey%3D4478395867%26time%3D1266261032&amp;volume=80&amp;type=flv');
    so.write('player');
    </script>
    </body>
    How to get red code with file_get_contents and &preg_match&?:)
    Thanks.
     
    Last edited: Feb 15, 2010
    dnsman, Feb 15, 2010 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if (preg_match('/file=(.*?)\'/', file_get_contents('http://whatever'), $matches))
       $red_code = $matches[1];
    PHP:
     
    SmallPotatoes, Feb 15, 2010 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    $page = file_get_contents('some_url.com/something_else');'

    Then something like this.

    
    preg_match('/file=(.*)\'\)/',$page,$urls);
    
    print_r($urls);
    
    PHP:
     
    jestep, Feb 15, 2010 IP
  4. dnsman

    dnsman Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks so much again!
     
    dnsman, Feb 15, 2010 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Without a ? after the *, it would also match any additional quoted attributes, if there were any.
     
    SmallPotatoes, Feb 15, 2010 IP