M
M
Magi2015-12-10 10:01:59
MySQL
Magi, 2015-12-10 10:01:59

How to correctly replace a link with a query in mysql?

Please tell me how to make a request. You need to remove the link from the title.

UPDATE `content` SET `title` = REPLACE( `title`, '<a href="telnet://*">', '' ) ;

Instead of * different IP addresses.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Max, 2015-12-10
@MaxDukov

UPDATE `content` SET `title` = REPLACE( `title`, 'old_ip', '' );

E
Evgeny Yablochkin, 2015-12-10
@Bers

UPDATE `content` 
SET 
  `title` = REPLACE(`title`, CONCAT('<a href="">', `field`, '</a>'),  '' );

M
Magi, 2015-12-10
@Magi

Perhaps I didn't phrase it correctly. In the title field inside the text there are links of the form <a href="telnet://192.168.1.1">(ip different) you need to remove them completely without deleting other text. I'll remove the closing </a>one with another request.

R
repeat, 2015-12-10
@repeat

Not the best option.

SELECT CONCAT(SUBSTRING_INDEX(withLink,'<', 1), REPLACE(SUBSTRING_INDEX(withLink,'>', -2),'</a>','')) as withoutLink FROM ...

-- for testing
SELECT 'something <a href="telnet://192.168.1.1">some text</a> dasdsdgdfg' as withLink, (SELECT CONCAT(SUBSTRING_INDEX(withLink,'<', 1), REPLACE(SUBSTRING_INDEX(withLink,'>', -2),'</a>',''))) as withoutLink

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question