text manipulation
Posted: Fri Oct 10, 2003 2:33 pm
I'm trying to write a script that will replace all instances where there are more than 2 spaces in a row with a single space.
I need to check to see if any spaces follow any new line characters and if so, remove them.
Then I need it to replace all instances where there are 3 or more newline characters with 2 newlines.
Here's the code i have that doesn't work right. It does everything but replace instances of 3 or more new line characters with 2 new lines.
Any idea what I'm doing wrong?
Thanks for everything.
I need to check to see if any spaces follow any new line characters and if so, remove them.
Then I need it to replace all instances where there are 3 or more newline characters with 2 newlines.
Here's the code i have that doesn't work right. It does everything but replace instances of 3 or more new line characters with 2 new lines.
Code: Select all
<?php
$input = (trim(stripslashes($_POSTї'input'])));
$output = ereg_replace(' +', ' ', $input);
$output = ereg_replace("\n +", "\n", $output);
$output = ereg_replace("(\n){3,50}", "\n\n", $output);
$output .= "\n\n\n<br><br><br>".'<a href="clean_text.html">Clean another file</a>';
print $output;
?>Thanks for everything.