문제

Could someone explaine me, why my code gives me nothing back?

<?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);
?>
도움이 되었습니까?

해결책

You're missing delimiters:

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

Also changed the non-greedy .*? to \w+ where \w is a shorthand to word characters so one or more [a-zA-Z_0-9]

다른 팁

That's not a well formed regular expression. You need to add delimiters:

<?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);
?>

Check it out in this fiddle: http://codepad.org/WSNCktk0

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top