preg_match_all error

Discussion in 'PHP' started by dizyn, Nov 22, 2007.

  1. #1
    		$title = ':(.*)./msU';
    		preg_match_all($title, $value, $matche);
    
    PHP:
    this gives me:
    Warning: preg_match_all() [function.preg-match-all]: No ending delimiter ':' found in C:\wamp\www\zzz\test.php on line 34
    :


    My Input:
    
    <li><a name="ChenFL02" href="../../indices/a-tree/c/Chen:Ping.html">Ping Chen</a>, <a href="../../indices/a-tree/f/Fu:Zhaohui.html">Zhaohui Fu</a>, <a href="../../indices/a-tree/l/Lim:Andrew.html">Andrew Lim</a>:
    The Yard Allocation Problem.
    3-8 <font size="-3"><a href="http://dblp.uni-trier.de/rec/bibtex/conf/aaai/ChenFL02">BibTeX</a></font>
    Code (markup):

     
    dizyn, Nov 22, 2007 IP
  2. undir.com

    undir.com Banned

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what are you trying to match?
     
    undir.com, Nov 22, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    "Andrew", I guess?

    Try this instead:
    
    "~:([^\.]+)~"
    
    PHP:
    $matche[1] should hold the result then.
     
    nico_swd, Nov 22, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    When using preg_match/_all you need to have the exact start/end character:

    Examples: /$PATTNER/ |$PATTERN| etc..

    Since you used ":" as the beginning character, it was expecting an ending character to be the same, thus the error "delimiter ':' not found'.

    If you only need to extract the name, then you will use this:

    
    preg_match_all('/:([.+])\.html/Us',$content,$results);
    
    PHP:
    $results[0] will contain the actual text it was found in, and $results[1] will contain the array of matches.

    Peace,
     
    Barti1987, Nov 22, 2007 IP
  5. dizyn

    dizyn Active Member

    Messages:
    251
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    I am trying to match between

    : and .

    you see:
    </a>:
    The Yard Allocation Problem.

    I wanted to fetch:
    "The Yard Allocation Problem"
     
    dizyn, Nov 22, 2007 IP
  6. dizyn

    dizyn Active Member

    Messages:
    251
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Please see:
    <a name="Walsh07" href="../../indices/a-tree/w/Walsh:Toby.html">Toby Walsh</a>:
    Uncertainty in Preference Elicitation and Aggregation.
    3-8 <font size="-3">

    I want to fetch 3-8 using "preg_match_all" any help, this is not constant, this a variable so can be changed but will be a number with "-" sign.
     
    dizyn, Nov 23, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    
    '~\s+(\d+-\d+) <font~'
    
    PHP:
     
    nico_swd, Nov 23, 2007 IP
  8. dizyn

    dizyn Active Member

    Messages:
    251
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #8
    thank you, so d will be used or int values, what we can use for strings?, so that "Uncertainty in Preference Elicitation and Aggregation" can be fetched.

    thank you
     
    dizyn, Nov 23, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    Strings are more complicated. The pattern depends totally on the string.
     
    nico_swd, Nov 23, 2007 IP
  10. dizyn

    dizyn Active Member

    Messages:
    251
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #10
    is there any tutorial where i can see this? Because i am very new to this.
     
    dizyn, Nov 23, 2007 IP
  11. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375