所以,让我说我有以下文字:
This is line number 1.
This is my line number 2.
This is his line number 3.
This is her line number 4.
This is their line number 5.
我想删除单词number
及其后面的所有内容并返回剩下的内容(当然是在不同的行上)。
我希望这是可能的,我没有过分复杂化这个问题,谢谢!
答案 0 :(得分:1)
strstr()是为你而制作的,同时还有爆炸
$string = 'This is line number 1.
This is my line number 2.
This is his line number 3.
This is her line number 4.
This is their line number 5.';
$ex = explode('.',$string);
var_dump($ex);
foreach ($ex as $x) {
echo strstr($x, 'number',true)."<br>";
}
答案 1 :(得分:0)
你可以使用strpos找到单词number
,然后对文本进行子串(每行循环都是这样)
http://php.net/manual/en/function.strpos.php。 http://php.net/manual/en/function.substr.php 在点和循环之后将文本分解为结果数组。希望它有所帮助,我是pnone
答案 2 :(得分:0)
所以这是工作示例:
$string = "This is line number 1";
$pos = strpos($string, "number");
if ($pos == false) {
print "Not found\n";
} else {
print "Found!\n";
print substr($string, $pos);
}
答案 3 :(得分:0)
str_replace(“number”,“”,$ actualstring)也可以正常工作。