-2
<html>
<body>
<form name='form' method='post' action="">
Dork: <input type="text" name="dork" id="dork" >
<input type="submit" name="submit" value="Submit">  
</form>
</body>
</html>
<?php 
$ptn = "/(?:[a-z]{4,5}://[a-z.0-9]*\/)?([a-z.\?_=]*)([0-9]*)/";  // Regex
$str = $_POST['dork']; //Your input, perhaps $_POST['textbox'] or whatever
$rpltxt = "$1";  // Replacement string
echo preg_replace($ptn, $rpltxt, $str);
?>

I got this error

Warning: preg_replace(): Unknown modifier '/'

How to fix it like this http://prntscr.com/ex29j2

2 Answers2

0

You are using unescaped slashes in the middle of your pattern: // The first slash defines the pattern end and the second gets therefore interpreted as a modifier. Escape both like:

/(?:[a-z]{4,5}:\/\/[a-z.0-9]*\/)?([a-z.\?_=]*)([0-9]*)/
Marc Anton Dahmen
  • 1,071
  • 6
  • 6
0

Escape the slashes:

$ptn = "/(?:[a-z]{4,5}:\/\/[a-z.0-9]*\/)?([a-z.\?_=]*)([0-9]*)/";  // Regex
//              here __^ ^

or use another delimiter

$ptn = "~(?:[a-z]{4,5}://[a-z.0-9]*/)?([a-z.?_=]*)([0-9]*)~";  // Regex
Toto
  • 89,455
  • 62
  • 89
  • 125