Page 1 of 1

How to remove part of a string

Posted: Tue Sep 16, 2014 8:18 am
by adsegzy
Hello friends,

Pls how do i remove part of a string. eg

Code: Select all

$position = "2, 5, 7, 10, 15"; // $position is an array
$old = '5';
How do I remove $old from $position so that it will be like this.

Code: Select all

$new_position = "2, 7, 10, 15";
Thanks
adsegzy

Re: How to remove part of a string

Posted: Tue Sep 16, 2014 9:34 am
by Celauran
You could use str_replace and replace the undesired bit with an empty string. You could explode into an array, unset the key, and implode back to a string. You could use preg_replace. There are a bunch of options.

Re: How to remove part of a string

Posted: Tue Sep 16, 2014 12:34 pm
by requinix

Code: Select all

$position = "2, 5, 7, 10, 15"; // $position is an array
Uh, no?