file_get_contents and regex

Discussion in 'PHP' started by Develop^, Aug 8, 2009.

  1. #1
    Hello,

    <?php
    
        $profilinfo = file_get_contents('URL');
    
        preg_match_all('#<form name="download_form" method="post" action="([^>]+)*">#', $profilinfo, $key);
    
        echo "Link: ";
          
        echo $key[0][0];
    ?>
    PHP:
    Between action=" and "> is the download-link. But with my code, my page is empty. Why? Is this a wrong regex?

    // Sorry for my english.
     
    Develop^, Aug 8, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    verify that $profilinfo is returning any content.
     
    kblessinggr, Aug 8, 2009 IP
  3. Develop^

    Develop^ Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, I have tested it.
     
    Develop^, Aug 8, 2009 IP
  4. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm not sure preg_match_all recognizes # , have you tried / in place of those?
     
    kblessinggr, Aug 8, 2009 IP
  5. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Do:

    
    action="([^"]+)">
    Code (markup):
     
    premiumscripts, Aug 8, 2009 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    It would've been better if I can see the HTML code. Try this:

    
    preg_match('#<form name="download_form" method="post" action="(.*)"#Us', $profilinfo, $key);
    
    PHP:
     
    ThePHPMaster, Aug 8, 2009 IP