PHP-删除一个以“”开头的完整字符串;作者”;


PHP - Remove a complete string that starts with "author"

如何删除总是以"author-"开头但连字符后面的完整字符串在每页上可能有所不同。

您可以使用以下preg_replace表达式

preg_replace("/^author-.*$/", "", $field);
if( false !== strpos( $string, 'author-' ) )
{
    unset( $string );
}

$string = preg_replace( '/author-.*/', '', $string );

(未测试)

是的,你可以使用pcre。

$string = "
title-one
author-two
date-three
who-author-
";
echo preg_replace('/^author'-.*$/m', '', $string);

我使用m修饰符来分别处理每一行