can someone that understands perl regular expressions tell me in plain english what the following code does?
$text = preg_replace("'([\r\n])[\s]+'", '\\\\1', $text);
i don't understand the \1 reference or the plus after the s. is it returning an escaped version of what it found (backreferrence)?
my input is text from a mysql database. i'm trying to output it in iCalendar format, which requires that lines longer than 76 "octets" (whatever that means) be "folded" by inserting a CRLF followed by a single space. here's my current function:
function iCal_wrap($text){
$text = preg_replace("'([\r\n])[\s]+'", '\\\\1', $text);
$text = wordwrap($text, 71, "\r\n ", 1);
return $text;
}
seems to function somewhat, iCal recognizes the output as valid, but sometimes spaces disappear. Also when i look at the text file output from iCal in dreamweaver i see \n wherever there is a line break, but in my output i see an actual line break, i.e., the text appears on a new line.
i don't clearly understand is the preg_replace function and i'm not terribly clear on CR vs LF issues. if anyone has any clarification to offer, it would much appreciated.