0

I have a string like this in the database

!80!n!98!n!22!n!6!n!76!n!1!n!24!n!129!n!59!n!73!n!7!n!40!n!85!n!35!n!42!n!126!n!81!n!37!n!128!n!147!n!106!n

I want to remove those ! and n symbols and want to add a pipe in between characters

80|98|22|6|76|1|24|129|59|73|7|40|85|35|42|126|81|37|128|147|106
NewUser
  • 12,713
  • 39
  • 142
  • 236

2 Answers2

1

you could update the column first:

UPDATE MyTable
SET StringColumn = REPLACE (StringColumn, '!n!', '|')
WHERE SomeOtherColumn LIKE '%PATTERN%'

More information on replace here: How can I use mySQL replace() to replace strings in multiple records?

Community
  • 1
  • 1
massie
  • 556
  • 2
  • 10
0
<?php
$str="!80!n!98!n!22!n!6!n!76!n!1!n!24!n!129!n!59!n!73!n!7!n!40!n!85!n!35!n!42!n!126!n!81!n!37!n!128!n!147!n!106!n
";
 $str1 = preg_replace('/\s+/','|',str_replace(array("!n","!","!n!"),' ',trim($str)));
 echo $output = substr($str1, 1, -1);

OUTPUT

80|98|22|6|76|1|24|129|59|73|7|40|85|35|42|126|81|37|128|147|106

Saty
  • 22,443
  • 7
  • 33
  • 51