Page 1 of 1

preg_match()???

Posted: Tue May 05, 2009 2:33 pm
by bobocheez
Hi, I found this bit of code and was wondering what is wrong here:

Code: Select all

 if(!empty($_POST)){
    $urls = explode("n",$_POST['urls']);
    foreach($urls as $url){
      $file = file_get_contents($url);
 
      preg_match("/?v=([^&]+)/",$url,$found);
      $id = $found[1];
      preg_match('/<meta name="title" content="([^"]+)">/',$file,$found);
      $title = $found[1];
I'm getting the error
Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 0 in .../index.php

here is the form but i looked it over....

Code: Select all

<form action="<?= $PHP_SELF ?>" method="post">
      <table>
        <tr>
          <td>
            List:<br />
            <textarea rows="10" cols="40" name="urls"></textarea><br />
            <input type="submit" value="Download" />
          </td>
        </tr>
      </table>
</form>

any help would be appreciated
thanks

Re: preg_match()???

Posted: Wed May 06, 2009 8:43 pm
by Gabriel
In your regular expression, "?" is a quantifier, or special symbol used in regular expressions. So tell it you mean the literal character with a backslash:
\?v=([^&]+)

Re: preg_match()???

Posted: Wed May 06, 2009 10:03 pm
by bobocheez
Thanks that fixed that problem, but...now it just does nothing

I don't know anything about php so if anyone is interested, here is where the script came from: http://www.protocoder.com/php/create-yo ... converter/