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? Link to comment https://forums.phpfreaks.com/topic/165248-solved-preg_match/ 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. Link to comment https://forums.phpfreaks.com/topic/165248-solved-preg_match/#findComment-871464 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. Link to comment https://forums.phpfreaks.com/topic/165248-solved-preg_match/#findComment-871504 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 Link to comment https://forums.phpfreaks.com/topic/165248-solved-preg_match/#findComment-871552 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. Link to comment https://forums.phpfreaks.com/topic/165248-solved-preg_match/#findComment-871590 Share on other sites More sharing options...
supermerc Posted July 9, 2009 Author Share Posted July 9, 2009 it still returns as no match Link to comment https://forums.phpfreaks.com/topic/165248-solved-preg_match/#findComment-871612 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. Link to comment https://forums.phpfreaks.com/topic/165248-solved-preg_match/#findComment-871861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.