[英]php replace string regex
I have a incoming value of: 我的传入值为:
"My Store Name - Tag - 30BG04S13G-2DST2 my item - My Store Name" “我的商店名称-标签-30BG04S13G-2DST2我的商品-我的商店名称”
set to :<?php echo $name; ?>
I'm trying to create a regex that will strip out the first part of the string so it looks like this: 我正在尝试创建一个正则表达式,它将去掉字符串的第一部分,因此它看起来像这样:
"30BG04S13G-2DST2 my item - My Store Name" “ 30BG04S13G-2DST2我的商品-我的商店名称”
I just need to strip this: "My Store Name - Tag - " off of the front 我只需要从前面剥掉“ My Store Name-Tag-”
If you know that your string will always begin with "My Store Name - Tag - ", then you can use the following via the preg_replace()
function: 如果您知道您的字符串将始终以“我的商店名称-标签-”开头,则可以通过preg_replace()
函数使用以下内容:
$input = preg_replace("^My Store Name - Tag - ", "", $input);
The expression itself simply uses the ^
character to indicate the start of the string, followed by the values you intend to strip out). 表达式本身仅使用^
字符表示字符串的开头,后跟要删除的值)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.