0

有人可以解释一下,为什么我的代码没有给我任何回报?

<?php
    $text = '<article about="about_text" typeof="sioc:Item foaf:Document" class="node node-bildergalerie node-published node-not-promoted node-not-sticky author-lalala odd clearfix" id="node-bildergalerie-6835">';
    $search_for = '(author\-.*?)\s';
    $replace = '';
    print preg_replace($search_for, $replace, $text);
?>
4

2 回答 2

2

您缺少分隔符

$search_for = '~(author\-\w+)\s~';

还将non-greedy 更改.*?\w+where \wis a shorthand to word characters so one or more[a-zA-Z_0-9]

于 2014-01-03T07:21:29.037 回答
1

这不是一个格式良好的正则表达式。您需要添加分隔符:

<?php
    $text = '<article about="about_text" typeof="sioc:Item foaf:Document" class="node node-bildergalerie node-published node-not-promoted node-not-sticky author-lalala odd clearfix" id="node-bildergalerie-6835">';
    $search_for = '/(author\-.*?)\s/';
    $replace = '';
    print preg_replace($search_for, $replace, $text);
?>

在这个小提琴中检查一下:http: //codepad.org/WSNCktk0

于 2014-01-03T07:24:52.327 回答