Just wondering if you can help me out with something. I have a string with a seri开发者_如何学编程es of numbers like 58498, 53980, 84578. Always 5 numbers in the series. Whats the best way to go about removing these?
You could do it with a regex.
$new_string = preg_replace("/\d{5},?/",'',$string);
preg_replace
(php doc).
You can find the 5-number strings using the pattern: /\d{5}/g
and remove each occurrence.
Use it like this:
$string = preg_replace("/\d{5}/g", "", $string);
(the g is for global (all occurrences))
If you want to get them (not remove them) then you should use:
preg_match
(php doc)
Use it like this:
$matches = array();
preg_replace("/\d{5}/g", $matches);
foreach($matches as $match) {
// do something with each $match
}
精彩评论