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]
Question
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);
?>
Solution
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]
OTHER TIPS
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