php - How to preg_replace from indentifier to end of text with CR(LF) characters -
i'm trying split piece of text (actually html) 2 pieces, top , bottom part. 'identifier' (<--#split#-->) in text marks position split.
to upper part have following preg_replace work:
$upper = preg_replace('/<--#split#-->(\s*.*)*/', '', $text);
this leaves me text comes before '<--#split#-->'.
to lower part came following preg_replace not work correctly:
$lower = preg_replace('/(\s*.*)*<--#split#-->/', '', $text);
this returns empty string.
how can fix second one?
it better use:
explode('<--#split#-->', $text);
example code:
$text = 'foo bar<--#split#-->baz fez'; $temp = explode('<--#split#-->', $text); $upper = $temp[0]; $lower = (count($temp > 1) ? $temp[1] : ''); // $upper == 'foo bar' // $lower == 'baz fez'
Comments
Post a Comment