I have a potentially very large list of submit type input buttons which are named delete0, delete1, delete2 and so on, and I’m trying to use preg_match to match the clicked button in the $_POST array and tease out the appended number, so I can delete that number from a mysql table.
The problem is that my preg_match is not behaving greedily when it seems it should be. For example, if I submit with button delete13, I’ll get a match for delete1, with delete23 I get a match for delete2, etc.
Below is my pattern and logic:
$pattern = "/,?(delete)(\d)+,?/";
$allpostkeys = implode(",", array_keys($_POST));
echo "<br />" . $allpostkeys . "<br />";
if (preg_match($pattern, $allpostkeys, $matches))
{
echo "<br />You elected to delete row: " . $matches[2];
$rowToDelete = $matches[2];
}
Change
into