简体   繁体   中英

php replace string regex

I have a incoming value of:

"My Store Name - Tag - 30BG04S13G-2DST2 my item - My Store Name"

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"

I just need to strip this: "My Store Name - Tag - " off of the front

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:

$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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM