Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    39
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Help with stopping preg_match

    How would I go about getting this to stop at an "&" or a quotation mark?

    PHP Code:
    else if (preg_match('#http://www.random.com/swf/(.+)#si'$match$id)) 
    I'm not sure what it does as is exactly, if that could be explained as well, thank you!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This is the wrong forum, moving from snippets to PHP.
    It captures any characters after /swf/. To skip, try using #http://www.random.com/swf/([^&\'"]+)#si.
    Not sure why you're worried about quotations; those cannot be provided as a part of the url.

  • #3
    New Coder
    Join Date
    May 2011
    Posts
    39
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Well it's for grabbing part of a video player embed. I want for it to grab anything after the /swf/, except stop once it gets to a " & " or a " " " while excluding them from the $id as well.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Oh I see from a scrape or something of the sorts.
    That should do it.

  • #5
    New Coder
    Join Date
    May 2011
    Posts
    39
    Thanks
    13
    Thanked 0 Times in 0 Posts
    That code doesn't seem to stop it at the first "&", it stops it at the second "&" though...

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by Suffice View Post
    That code doesn't seem to stop it at the first "&", it stops it at the second "&" though...
    My test says otherwise:
    PHP Code:
    <?php
    $pattern 
    '#http://www.random.com/swf/([^&\'"]+)#si';
    $str 'this is a <a href="http://www.random.com/swf/teststuffs&a=a&b=b">an example</a> with a
       link from http://www.random.com/swf/somextrastuffs&done=done in it.'
    ;

    if (
    preg_match_all($pattern$str$matches))
    {
        
    printf("<pre>%s</pre>"print_r($matchestrue));
    }


    ?>
    Code:
    Array
    (
        [0] => Array
            (
                [0] => http://www.random.com/swf/teststuffs
                [1] => http://www.random.com/swf/somextrastuffs
            )
    
        [1] => Array
            (
                [0] => teststuffs
                [1] => somextrastuffs
            )
    
    )
    The results are multidimensional since I used a preg_match_all instead. Preg_match will be single.

    Unless there's something I'm missing from the criteria?

  • #7
    New Coder
    Join Date
    May 2011
    Posts
    39
    Thanks
    13
    Thanked 0 Times in 0 Posts
    That does seem to be the case...


    PHP Code:
    $s file_get_contents($VideoSite);     

    $patterns = array();
    $patterns[] = '<embed[^>]+src="(.+?)"';
    $patterns[] = '<iframe[^>]+src="(.+?)"';
    $patterns[] = '<object[^>]+src="(.+?)"';

    $patterns "#(?:" implode("|"$patterns) . ")#si";

    preg_match_all($patterns, ($s), $m);
    if (!empty(
    $m[0]))

            
    $edata = array();
            foreach(
    $m[0] as $match)
            { 
                    if (
    preg_match('#http://www.dailymotion.com/swf/(.+)"#si'$match$id))
                    
    $edata[] = "[dailymotion " $id[1] . "]";


    Sorry, I didn't really think it was the other part of the code. Anyways I still don't know how to deal with it...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •