douyan1896 2012-07-08 11:02
浏览 56

PHP - 从字符串中删除特定字符串

I've got this string, but I need to remove specific things out of it...

Original String: hr-165-34.sh-290-92.ch-215-84.hd-180-1.lg-280-64.

The string I need: sh-290-92.ch-215-84.lg-280-64.

I need to remove hr-165-34. and hd-180-1. !

EDIT: Ahh ive hit a snag!

the string always changes, so the bits i need to remove like "hr-165-34." always change, it will always be "hr-SOMETHING-SOMETHING."

So the methods im using wont work!

Thanks

  • 写回答

5条回答 默认 最新

  • duancu4731 2012-07-08 11:06
    关注

    The easiest and quickest way of doing this is to use str_replace

    $ostr = "hr-165-34.sh-290-92.ch-215-84.hd-180-1.lg-280-64";
    $nstr = str_replace("hr-165-34.","",$ostr);
    $nstr = str_replace("hd-180-1.","",$nstr);
    
    评论

报告相同问题?