Q:

PHP Remove everything except numbers from string

I am using AJAX to retrieve the ID of a certain HTML element. The HTML ID is constructed like "sqlitem_1", "sqlitem_2", "sqlitem_3" etc. and each number corresponds to a record in the database. 
I tried preg_replace('/\D/', '', $item);where $item is the string I need to cut, but this didn't do the trick.

A:

Please note that preg_replace doesn't change the argument but rather returns the new value. You might wanna check the preg_replace manual.
So what you need to do is assign the returned value
$item = preg_replace('/\D/', '', $item);

instead.

