如果单词存在,如何删除行? (PHP)
嘿,如果其中存在单词,我想删除整行吗?通过PHP?
示例:你好世界,这个世界很震撼
。 它应该做的是:如果它找到单词 hello
它应该删除整行。 我该怎么做,括号和引号之间也可能有单词。
谢谢。
Hey, I want to remove the whole line if a word exists in it? through PHP?
Example: hello world, this world rocks
.
What it should do is: if it finds the word hello
it should remove the whole line.
How can i do that and there could be words in between brackets and inverted commas also.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
输出
CodePad。
你说这个词可能是也可能是括号和引号之间的词。
如果只需要单词本身或括号和引号之间的单词,您可以将
strstr()
替换为...Ideone。
我假设括号表示括号,引号表示双引号。
您还可以在多行模式下使用正则表达式,但是乍一看此代码的作用并不那么明显...
相关问题。
Output
CodePad.
You said the word could be could be words in between brackets and inverted commas also too.
In the case of wanting the word only on its own, or between bracket and quotes, you could replace the
strstr()
with this...Ideone.
I assumed by brackets you meant parenthesis and inverted commas you meant double quotes.
You could also use a regex in multiline mode, however it won't be as obvious at first glance what this code does...
Related Question.
如果您有一个像这样的行数组,
您可以循环遍历该数组并查找单词
int stripos ( string $haystack , string $needle [, int $offset = 0 ] )
: http://www.php.net/manual/en/function.stripos.phpIf you have an array of lines like so
You can loop through the array and look for the word
int stripos ( string $haystack , string $needle [, int $offset = 0 ] )
: http://www.php.net/manual/en/function.stripos.php又好又简单:
Nice and simple: