0

I want to get the oID parameter from this HTML source with a regex condition:

<img src="button_print.gif" style="cursor:hand" onclick="window.open('http://domain.com/print_order.php?oID=5', 'popup', 'toolbar=0, width=640, height=600')">

I´ve tried many different ways now but I´m unable to find the right way. For my understanding this regex should work (but it doesn´t):

oID=(\d+)

Maybe somebody has a hint for me?

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
Michael
  • 2,966
  • 3
  • 30
  • 33

1 Answers1

1

You have to replace the string before and after the match too:

.*?oID=(\d+).*

The command:

$string = '<img src="button_print.gif" style="cursor:hand" onclick="window.open(\'domain.com/print_order.php?oID=5\', \'popup\', \'toolbar=0, width=640, height=600\')">'; 
var_dump(preg_replace('/.*?oID=(\d+).*/','Output: $1',$string));

The result:

Output: 5

Online test.

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168