2016-09-27 24 views
-2

我有这个字符串如何在php中删除部分字符串?

NOTEBOOK > ABC 
TABLET > DFG 

我想删除一切后 '>' 包括 '>'

我想这

$category = substr($categoryGet,0,strrpos($categoryGet.">",">")); 

没有结果到目前为止

+0

在换行符上爆炸,然后在“>”上爆炸 – nogad

+0

为什么要将'>>“'连接到字符串?它总能找到你添加的字符,而不是字符串中的字符。 – Barmar

回答

1

您可以使用preg_replace

$category = preg_replace('/>[^>]*$/m', '', $category); 

正则表达式匹配>后跟任何非>字符,直到行尾。 m修饰符使得$匹配字符串中每行的结尾。

+0

不知道是否“NOTEBOOK> ABC片”是他想要的返回 – nogad

+0

号nogad,'NOTEBOOK' 'TABLET'这就是我想要的 – Alexxxx

+0

@nogad我修改它使用'm'修饰符行工作。 – Barmar

0
$str="NOTEBOOK > ABC 
TABLET > DFG"; 

$x=explode("\n",$str); //break by lines 

foreach($x as $y){ 
$k=explode('>',$y); 

echo trim($k[0]); //or that ever form you want the output to be 
} 
相关问题