jasondavis wrote:because ... it would give errors from mysql
If you were inserting it straight into a database query which is something you should NEVER do with user-supplied input.
Which is of course why you're wanting to parse and validate the input - not because a trailing comma would "give errors from mysql" but because you don't want to get thoroughly burned.
A PCRE regular expression would be
\d+(,\d+)*
More checking (to avoid things like 235743587632857648756357836578265782652657827826578265782657825,23875628562378562378562785627856278567823657826578265782 or 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6)
$ids = array_unique(array_map('intval', explode(',', $_GET['id'])));
$id_string = join(',', $ids);