开发者

PHP Regex Last Entry with Sperators

Sorry my regex skills are horrible. I am trying figure out how to just get the final entry in a text file i am manipulating. So the line of data is...

Paint & Maintenance///Cleaners, Soaps & Polishes///Vinyl Cleaners & Protectors

I need only the string of data that shows up after the last "///" (Vinyl Cleaners & Protectors) but the number of separators ("///") will vary each time.

Any Help is greatly app开发者_JAVA技巧reciated!


Don't need regex for that:

$delim = '///';
$str = 'Paint & Maintenance///Cleaners, Soaps & Polishes///Vinyl Cleaners / Protectors';
$str = substr($str, strrpos($str, $delim)+strlen($delim));

Edit:

Using native string functions is much faster than a regex expression. As a general rule, only use regex when absolutely necessary.


$last_item = array_pop(preg_split('|///|', $str));

(Edit: I think I misunderstood your statement about number of separators, adjusted.)


preg_match('/\/+(.+)$/',$in,$m); echo $m[1];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜