You can do it with 1 update sql query. I prepared you a test table, and update query to demonstrate.
Basically to use on your own table, JUST change table name from TestTable to your table s name and change the name of "Field" to your fields name which you want to update.
If you have multiple a href links in one field. You need to execute query multiple times.
You can find maximum link occurences in your table with first query. Than execute update query multiple times. When you update your query at the count of occurence_count than update 1 more query I gave you for clearing some temp data I used.
-- find maximum link occurences in your table
SELECT max(cast((LENGTH(Field) - LENGTH(REPLACE(Field, <a href , ))) / 7 as unsigned)) AS occurrence_count
FROM TestTable;
<>-> • 更新你的表格,以取代所有红外线。
update TestTable
set Field = replace
(
@b:=replace
(
@a:=replace(Field
, substring(Field, Instr(Field, "<a href= "), Instr(Field, "</a>")-Instr(Field, "<a href= ")+4)
, replace(substring(Field, Instr(Field, "<a href= "), Instr(Field, "</a>")-Instr(Field, "<a href= ")+4), "_", "-")
)
, substring(@a, Instr(@a, "<a href= "), Instr(@a, "</a>")-Instr(@a, "<a href= ")+4)
, replace(substring(@a, Instr(@a, "<a href= "), Instr(@a, "</a>")-Instr(@a, "<a href= ")+4), "<a href=", "<*a href=")
)
, substring(@b, Instr(@b, "<*a href= "), Instr(@b, "</a>")-Instr(@b, "<*a href= ")+4)
, replace(substring(@b, Instr(@b, "<*a href= "), Instr(@b, "</a>")-Instr(@b, "<*a href= ")+4), "</a>", "</*a>")
)
;
- ——在您的所有更新工作完成之后,从小链条链条中清除星体。
update TestTable set Field = replace(replace(Field, "<*a href", "<a href"), "</*a>", "</a>")
<>-> 页: 1
select * from TestTable;
<><>TEST TABLE>
CREATE TABLE `testtable` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`Field` VARCHAR(255) NOT NULL DEFAULT ,
PRIMARY KEY (`id`)
)
COLLATE= latin1_swedish_ci
ENGINE=MyISAM
ROW_FORMAT=DEFAULT
<><>TEST DATA
Insert into TestTable (Field) values ("Hello, my name is <a href= http://example.com/joe_smith >joe smith</a> and I eat pizza with my friend <a href= http://example.com/john_doe >john doe</a>");
Insert into TestTable (Field) values ("Hello, my name is <a href= http://example.com/joe_smith >joe smith</a> and I eat pizza with my friend <a href= http://example.com/john_doe >john doe</a> my friend <a href= http://example.com/john_doe >jane doe</a>");