Jump to content

[SOLVED] preg_match


supermerc

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.