shahrukh1 Posted December 7, 2012 Share Posted December 7, 2012 need to extract the hash value from this string id="Qform__FormState" value="c49c31100c139a92a85a1dc37fb399c5" proposed expression: $expression = '#^([a-z0-9]{32})$#i'; does not work tried this one as well $expression = '#id=\"Qform__FormState\" value=\"^([a-z0-9]{32})$\"#i'; no luck either Link to comment https://forums.phpfreaks.com/topic/271735-hash-key/ Share on other sites More sharing options...
Jessica Posted December 7, 2012 Share Posted December 7, 2012 Hashes are one way. Sooooo... Too bad. Link to comment https://forums.phpfreaks.com/topic/271735-hash-key/#findComment-1398174 Share on other sites More sharing options...
Jessica Posted December 7, 2012 Share Posted December 7, 2012 Or if you're saying you want to get the actual hash, then use a Dom parser. Link to comment https://forums.phpfreaks.com/topic/271735-hash-key/#findComment-1398175 Share on other sites More sharing options...
shahrukh1 Posted December 7, 2012 Author Share Posted December 7, 2012 no i just need that value tag from a webpage there is a snippet from the webpage Link to comment https://forums.phpfreaks.com/topic/271735-hash-key/#findComment-1398180 Share on other sites More sharing options...
requinix Posted December 8, 2012 Share Posted December 8, 2012 DOMdocument. getElementById() then the "value" attribute of that element. Link to comment https://forums.phpfreaks.com/topic/271735-hash-key/#findComment-1398182 Share on other sites More sharing options...
.josh Posted December 8, 2012 Share Posted December 8, 2012 The most immediate reason why your regex is failing is because ^ and $ tell the regex engine to match the beginning and end of string. So in other words, you are telling the regex engine that the whole string must be that hash, nothing else. If you remove those anchors, you will get it to match. However... it will match any 32 alphanumeric substring within the content you are scraping. Ideally you should use a DOM parser like requinix suggested, but if you really must go the regex route, this will work and is fairly flexible: $expression='#(id\s*=\s*["\']Qform__FormState["\'][^>]*)?([a-z0-9]{32})(?(1)|[^>]*id\s*=\s*["\']Qform__FormState["\'])#i'; This will allow for some format variation tolerances: random spacing, order of attributes, and quotes. The matched hash will be in $match[2] Link to comment https://forums.phpfreaks.com/topic/271735-hash-key/#findComment-1398188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.