searching substring including double quotes

Discussion in 'PHP' started by mahmood, Jan 20, 2006.

  1. #1
    Hi
    Say I want to search a text for a part which includes double quote. I can't use strpos for it. What else can I do.

    Say I am looking for (one"two):the following two code wouldn't work:
    
    $myString = strpos($text,"one"two");
    
    $myString = strpos($text,"one\"two");
    
    PHP:


    Any Idea?
     
    mahmood, Jan 20, 2006 IP
  2. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2

    This should be a good start.

    preg_match_all('([a-z0-9]+"[a-z0-9]+)', $text, $matches)

    this will return $matches, which is an array of all the found results:

    
    Array
    (
        [0] => Array
            (
                [0] => one"two
                [1] => this"may
                [2] => future"stuff
            )
    
    )
    
    
    Code (markup):
    -the mole

    PS,

    use preg_match_all('([a-z0-9]+"[a-z0-9]+)', $text, $matches, PREG_OFFSET_CAPTURE) to get the string offset
     
    themole, Jan 20, 2006 IP
  3. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    You could also try this:
    $myString = strpos($text,'one"two');
    PHP:
     
    Triexa, Jan 21, 2006 IP