<a href="http://www.domain.com?blahblah=blahblah">MyLink</a> 


$pattern = "[\"].[\"]";
preg_match($pattern, $text, $matches);

I am trying to get the URL within the double quotes ... have frantically googled it like crazy but keep getting things like this:

Warning: preg_match(): Unknown modifier '.' in ...[line where preg is called]

Any help on this would be greatly appreciated !!

php -v
PHP 5.2.13 (cli) (built: Mar 17 2010 04:08:01)

gvanto

    Ah OK I found it, it's here (not sure why getting above errors tho)

    $pattern = '/<a href="(.+)">/';
    
    echo $pattern;
    
         preg_match($pattern, $text, $matches);
    
    $href = $matches[1];
    
    

      It's because you were missing the pattern delimiters in the original expression (the characters that separate the regex from its modifiers. the regex parser assumed that the delimiters were therefore [font=monospace][[/font]...[font=monospace]][/font], making the entire regex [font=monospace][\"][/font] followed by something it didn't expect to see.

        Oh ic, thanks for that weedpacket (well done for 20k posts!). Here's a shorter regex :

        $pattern = '/"(.+)"/';
        
        echo $matches[0];
        

        //I am curious how the matching works too - how come $matches[1] is without the quotes?

          Matches[0] is the entire pattern match, matches[1] (and up) is the first matching sub-pattern. In this case your sub pattern is (.+) while you're entire pattern is "(.+)"

          HTH

            Write a Reply...