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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -