supermerc Posted July 8, 2009 Share Posted July 8, 2009 hey, Im using curl to go to a page and i want to get the hash for items, links look like this: /trade.php?tradeWith=7210&addItem=6919211&addHash=894882156e40dd8eedf3bb5b94c9d5f9 What i have right now is: $data = $result2; preg_match('~/trade.php?tradeWith=7210&addItem=6919211&addHash=([^"\']*)"~i',$data,$matches); but its returning empty.. anyone know why? Quote Link to comment Share on other sites More sharing options...
Mchl Posted July 8, 2009 Share Posted July 8, 2009 ? is regex special character. You need to escape it. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted July 8, 2009 Share Posted July 8, 2009 And the dot. Would probably not make a difference in your case, but when matching a dot, escape it. It would also make more sense to remove the last double quote in the pattern, since your previous match stops when a double or single quote appears. Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 8, 2009 Author Share Posted July 8, 2009 I know nothing about regex someone made that for me to get something else and I just changed it for this but i guess it didnt match.. So i dont understand what you both are saying :S Quote Link to comment Share on other sites More sharing options...
thebadbad Posted July 8, 2009 Share Posted July 8, 2009 Assuming the hash is a hexadecimal number: preg_match('~/trade\.php\?tradeWith=7210&addItem=6919211&addHash=([0-9a-f]*)~i', $data, $matches); Note that I escaped the dot and the question mark with a backslash, to suppress their special regex meaning. Quote Link to comment Share on other sites More sharing options...
supermerc Posted July 9, 2009 Author Share Posted July 9, 2009 it still returns as no match Quote Link to comment Share on other sites More sharing options...
thebadbad Posted July 9, 2009 Share Posted July 9, 2009 Did you solve it? Else show us the bit of $data where the URL occurs, and a print_r() of $matches. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.