preg_match()???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bobocheez
Forum Commoner
Posts: 25
Joined: Mon Oct 27, 2008 8:06 pm

preg_match()???

Post 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
Last edited by Benjamin on Tue May 05, 2009 2:34 pm, edited 2 times in total.
Reason: Added [code=php]..[/code] tags.
User avatar
Gabriel
Forum Commoner
Posts: 41
Joined: Wed May 06, 2009 8:12 pm
Location: Las Vegas

Re: preg_match()???

Post 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=([^&]+)
bobocheez
Forum Commoner
Posts: 25
Joined: Mon Oct 27, 2008 8:06 pm

Re: preg_match()???

Post 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/
Post Reply