PHP - 从字符串中去除特定字符串 [英] PHP - Strip a specific string out of a string

查看:40
本文介绍了PHP - 从字符串中去除特定字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个字符串,但我需要从中删除特定的东西...

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

原始字符串:hr-165-34.sh-290-92.ch-215-84.hd-180-1.lg-280-64.

我需要的字符串:sh-290-92.ch-215-84.lg-280-64.

我需要删除 hr-165-34.和 hd-180-1.!

啊,我遇到了障碍!

字符串总是会改变,所以我需要删除像hr-165-34"这样的位.总是改变,它总是hr-SOMETHING-SOMETHING."

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!

谢谢

推荐答案

取决于您为什么要完全删除那些 Substrigs...

Depends on why you want to remove exactly those Substrigs...

  • 如果你总是想完全删除那些子字符串,你可以使用 str_replace
  • 如果总是想去掉同一位置的字符,可以使用substr
  • 如果您总是想删除两个点之间的符合特定条件的子字符串,您可以使用 preg_replace

这篇关于PHP - 从字符串中去除特定字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆