Forum Moderators: coopster
what does the last regex do? how would your write it to fix something like:
-------------------------------------
this is a text
another line
another line
another line
-------------------------------------
thank you for your help! :)
function scrub_da_post($content)
{
// turn returns to newlines:
$content = str_replace("\r", "\n", $content);
// turn tabs to spaces:
$content = str_replace("\t", " ", $content);
// next is searching for double spaces.
while(preg_match("/ /i", "$content"))
{
// replace them with single spaces:
$content = str_replace(" ", " ", $content);
}
// looks for spaces after a newline:
while(preg_match("/\n /", "$content"))
{
// remove that space:
$content = str_replace("\n ", "\n", $content);
}
// look for two newlines:
while(preg_match("/\n\n/i", "$content"))
{ // turn it to one newline
$content = str_replace("\n\n", "\n", $content);
}
// the \n now separates paragraphs; change \n to <p>:
$content = "<p>" . str_replace("\n", "</p><p>", $content) . "</p>";
$content = str_replace("<p></p>", "", $content);
// done!
return $content;
}
$message=preg_replace("/\n[^\w]*\n/","\n",$message);what does the last regex do?
It finds any two newlines and replaces them for one, ignoring anything in between them which is not a word charecter. for example \nSo\n wouldn't get caught by \n \n or \n\t\n would get caught - eg, it ignores whitespace
although I just noticed something... it won't be possible to have paragraphs is it's like this...
maybe it should let it have \n\n or everything will be just one block of text...
then the change should be that if there's over \n\n, change it to that... if there's two or one, just leave it alone
how would the regex be changed to do this? ^^;;