F
F
freshik3122018-02-22 23:39:24
PHP
freshik312, 2018-02-22 23:39:24

How to remove part of a string?

There is a line: 1,2,4,5,6,7,9,15,16... i.e. any numbers through ","
The numbers can be different and in a different order, you need to remove from this line, for example 4 (1,2,5,6,7,9...)
how to implement it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-02-22
@0xD34F

implode(',', array_filter(explode(',', $str), function($n) {
  return $n !== '4';
}))

or
or
substr(str_replace(',4,', ',', ",$str,"), 1, -1)

A
Andrey, 2018-02-23
@VladimirAndreev

preg_replace('/\,4$/','',str_replace(',4,', ',',$str));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question