I have done my research on the subject and I thought about using replace, but the trouble is if I replaced with nothing, then I will end up with lots of spaces in my database field which will get very messy. So I have come to you guys for help.
I have a field in my database called EQUIPMENT. This is an example of what is in one of the fields
15<>5<>6<>3<>2<>1<>14<>13<>12
Each number is representing the ID of a piece of equipment. How would I go about deleting for example <>6 As I said, I looked at using replace but replacing it with ' ' would leave spaces in the field.
Replace with '' (no space) should not leave a space. You could also use trim, if you don't want any whitespaces.
I m not sure if this is what you want, but before inserting value just use:
echo str_replace("<>", "", "15<>5<>6<>3<>2<>1<>14<>13<>12");
Output: 1556321141312
To delete <>6
use echo str_replace("<>6", "", "15<>5<>6<>3<>2<>1<>14<>13<>12");
Outcome: 15<>5<>3<>2<>1<>14<>13<>12
If you want to do this on mysql database then this could help you: https://stackoverflow.com/a/14586441/5459942
Instead of replacing a "<>number" by an empty string, you can replace a "<>number<>" by "<>".
This is to avoid that other numbers (that contain that number) are also replaced partially.
And to avoid a wrong result when the number is at the start or the end of the string, a '<>' is concatinated to both ends.
Then those '<>' at both ends can be trimmed after the replace.
Example:
select
EQUIPMENT,
TRIM(BOTH '<>' FROM REPLACE(CONCAT('<>',EQUIPMENT,'<>'),CONCAT('<>',6,'<>'),'<>')) as Equipment_without_6
from
(
select '15<>5<>6<>3<>2<>1<>14<>13<>12' as EQUIPMENT
union all select '6<>16<>6<>60<>6'
) q
Returns:
EQUIPMENT Equipment_without_6
------------------------------ ---------------------------
15<>5<>6<>3<>2<>1<>14<>13<>12 15<>5<>3<>2<>1<>14<>13<>12
6<>16<>6<>60<>6 16<>60