我在数据库中有这样的字符串
!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
我想删除那些!和n个符号,并希望在字符之间添加管道
80|98|22|6|76|1|24|129|59|73|7|40|85|35|42|126|81|37|128|147|106
答案 0 :(得分:1)
您可以先更新列:
UPDATE MyTable
SET StringColumn = REPLACE (StringColumn, '!n!', '|')
WHERE SomeOtherColumn LIKE '%PATTERN%'
有关替换的更多信息: How can I use mySQL replace() to replace strings in multiple records?
答案 1 :(得分: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);
输出
80 | 98 | 22 | 6 | 76 | 1 | 24 | 129 | 59 | 73 | 7 | 40 | 85 | 35 | 42 | 126 | 81 | 37 | 128 | 147 | 106