Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何删除始终以“author-”开头但在连字符之后的完整字符串可能在每个页面上有所不同。
您可以使用以下preg_replace表达式
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 修饰符分别处理每一行