mercredi 1 juillet 2015

Using preg_match on array from POST checkbox values

The problem I'm having is making preg_match work correctly for my array returned from my form.

<input type="checkbox" name="receiver-check[]" class="checkbox-id" value="Username 1 (123)">
<input type="checkbox" name="receiver-check[]" class="checkbox-id" value="Username 2 (456)">
<input type="checkbox" name="receiver-check[]" class="checkbox-id" value="Username 3 (789)">

So I wish to use preg_match on the values received through my form. This is how I use it.

$msg_receivers = $_POST['receiver-check'];
$count_receivers = count($msg_receivers);

$while_count = 0;
while($count_receivers >= ($while_count + 1)){
    preg_match_all('(?<=\()(.+)(?=\))', $msg_receivers[$while_count], $msg_receiver_query);

    // QUERY FOLLOWS

    $while_count ++;
}

Then I use $msg_receiver_query to asign a value in the query INSIDE the while loop. What I currently receive in my database is 0 and 1. Nothing else. What would the correct preg_match be for me to output JUST the numbers inside the paranthesis? and is there a more effective solution to this problem of mine?




Aucun commentaire:

Enregistrer un commentaire