MySQL的REPLACE()是PHP的STR_REPLACE()

The PHP function that I use the most could be str_replace(). If you aren't familiar with the function, here's what it does:

我使用最多PHP函数可能是str_replace() 。 如果您不熟悉此功能,请执行以下操作:

$string = 'Hello_My_Friend';
$result = str_replace('_', '-', $string);  //becomes Hello-My-Friend

Over the past months, I've grown to realize that I oftentimes use the function as a quick fix. I've been using MySQL's version of str_replace() a lot lately in an effort to cleanse the sins of my programming past. Here's a basic usage of MySQL's REPLACE function:

在过去的几个月中,我逐渐意识到我经常使用该功能作为快速解决方案。 最近,我一直在使用MySQL的str_replace()版本,以消除我过去编程的过失。 这是MySQL的REPLACE函数的基本用法:

UPDATE website_content_pages SET content = REPLACE(content, 'b>', 'strong>');

The above code changes all <B> and </B> tags to <STRONG> and </STRONG> tags. Using MySQL's function allows me to fix the problem once instead of "re-fixing" it every time the page loads.

上面的代码将所有<B></B>标签更改为<STRONG></STRONG>标签。 使用MySQL的功能可以使我解决该问题一次,而不是每次页面加载时都“重新解决”它。

翻译自: https://davidwalsh.name/mysql-replace

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值