-5

如何删除始终以“author-”开头但在连字符之后的完整字符串可能在每个页面上有所不同。

4

3 回答 3

4

您可以使用以下preg_replace表达式

preg_replace("/^author-.*$/", "", $field);
于 2013-08-30T07:25:11.403 回答
1
if( false !== strpos( $string, 'author-' ) )
{
    unset( $string );
}

或者

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

(未测试)

于 2013-08-30T07:26:47.453 回答
0

是的,您可以使用pcre

$string = "
title-one
author-two
date-three
who-author-
";

echo preg_replace('/^author\-.*$/m', '', $string);

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

于 2013-08-30T07:34:23.957 回答