-1

I've been trying to use preg_match to find a form with a certain action URL. Here the code

if (!preg_match('/<form method="post" 
action="https[\:]//www.amazon.com/gp/aw/si.html/ref=aw_c_co".*?<\/form>/is', $page, $form)) {
die('Failed to CHECKOUT form!');

But I get an error message:

Warning: preg_match(): Unknown modifier '/'

I dont understand whats wrong. Thanks

Emilios1995
  • 487
  • 5
  • 20

2 Answers2

0

You have to escape (\) the / since these are your regex delimiters! Maybe you want to use other delimiters?

/ -> \/

MasterD
  • 128
  • 2
  • 6
  • To avoid "toothpick syndrome" (all those \ and /), change your outer pattern delimiters from / to something else like ~ or #. You don't need to escape a colon : but you should escape literal periods: `'~
    ~is'`.
    – Phil Perry Jun 18 '14 at 13:19
0

You can use the following code :

$str = '<form method="post" action="https[\:]//www.amazon.com/gp/aw/si.html/ref=aw_c_co".*?<\/form>';
$str = preg_replace('^.*<form.*?action="(.+?)".*$', '$1', $str);

It give you : https[\:]//www.amazon.com/gp/aw/si.html/ref=aw_c_co

Good luck

Samuel Dauzon
  • 10,744
  • 13
  • 61
  • 94