删除某个字符后的字符串部分 [英] Remove portion of a string after a certain character

查看:96
本文介绍了删除某个字符后的字符串部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何删除PHP中某个子字符串之后的所有内容

I'm just wondering how I could remove everything after a certain substring in PHP

例如:

Posted On April 6th By Some Dude

我想拥有它,以便它删除所有包含子字符串"By"及其后的文本

I'd like to have it so that it removes all the text including, and after, the sub string "By"

谢谢

推荐答案

$variable = substr($variable, 0, strpos($variable, "By"));

用简单的英语说:给我字符串的一部分,从开始到结束,直到您第一次遇到分隔符的位置.

In plain english: Give me the part of the string starting at the beginning and ending at the position where you first encounter the deliminator.

这篇关于删除某个字符后的字符串部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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