text manipulation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

text manipulation

Post 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.
murph
Forum Commoner
Posts: 29
Joined: Fri Oct 03, 2003 1:28 pm
Location: washington

Post by murph »

i believe str_replace would work better.
Post Reply