Page 1 of 1

text manipulation

Posted: Fri Oct 10, 2003 2:33 pm
by EricS
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.

Code: Select all

<?php

$input = (trim(stripslashes($_POST&#1111;'input'])));

$output = ereg_replace(' +', ' ', $input);
$output = ereg_replace("\n +", "\n", $output);
$output = ereg_replace("(\n)&#123;3,50&#125;", "\n\n", $output);

$output .= "\n\n\n<br><br><br>".'<a href="clean_text.html">Clean another file</a>';

print $output;

?>
Any idea what I'm doing wrong?

Thanks for everything.

Posted: Fri Oct 10, 2003 2:50 pm
by murph
i believe str_replace would work better.