preg match - Matching problem

Discussion in 'PHP' started by Silver89, Feb 18, 2009.

  1. #1
    I'm trying to match this string but hitting a few problems?

    The string:
    complete_str += 'ar.com%2fcached%2fs%22%3e%0d%0a%3c%2fSCRIPT%3e';
    Code (markup):

    What I'm using:

    
    $html = @file_get_contents("$jsUrl");
    
    preg_match_all('~complete_str += \'(.*?)\';~s', $html, $titleMatches);
    
    foreach ($titleMatches[1] AS $titleMatch)
    				{ 
    				echo "complete_str: $titleMatch<br /><br />";
    				}
    Code (markup):

     
    Silver89, Feb 18, 2009 IP
  2. dowhile

    dowhile Active Member

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #2
    You need to escape "+". Because it has special meaning.

    preg_match_all('~complete_str \+= \'(.*?)\';~s', $html, $titleMatches)
     
    dowhile, Feb 18, 2009 IP