Attempting* to use reg exp. Guidance needed O:)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    Attempting* to use reg exp. Guidance needed O:)

    So, i'm making a proxy, cos, well, i'm bored. I thought it'd be rather easy actually.. but alas, it requires reg exp's - one of my pet hates; just below class's.

    Anyway, the code im using:
    [php]
    $_string = file_get_conten ts("http://myspace.com"); // myspace file.

    $_reg = '#\"http://(.*)\"#'; // regular expression

    preg_match($_re g, $_string, $_match);
    echo htmlentities($_ match[0]);
    [/php]
    This works... but it gives me this:
    Code:
    "http://x.myspacecdn.com/Modules/Common/Static/img/iphone.png" /><meta http-equiv="expires" content="0" /><meta http-equiv="Pragma" content="no-cache"
    when what i actually want is:
    Code:
    "http://x.myspacecdn.com/Modules/Common/Static/img/iphone.png"
    It stretches to the last quote on the current line.. when i want the first quote that comes after href=

    Any ideas?
  • oberon
    New Member
    • Mar 2008
    • 14

    #2
    Instead of matching with .*, you could match with [^\"]*. That way you will only match until first occurence of \".
    Code:
    $_reg = '#\"http://([^\"]*)\"#'; // regular expression

    Comment

    Working...