Page 1 of 1

Need help trimming text

Posted: Tue May 24, 2005 4:29 pm
by jolinar
I'm working on some PHP code and I am creating a system where text is read line by line from a file and adds it to a list in alternating lines so the odd lines are the title and even lines are the content:

Code: Select all

$counter = 0;
		
		foreach ($data as $line) {
			if( $counter % 2 == 0 ) {
				$field = $line;
			}
			else {
				$this->sitedata[$field] = $line;
			}
			$counter++;
		}
It seems to work except I need to trim the line delimiters from the end, can anyone suggest a simple way of doing this? (I'm a bit of a numpty here)

Posted: Tue May 24, 2005 4:31 pm
by John Cartwright
what are your line delimeters?

most likely a quick str_replace() shoud help

Posted: Tue May 24, 2005 4:34 pm
by jolinar
a newline (not sure if delimiter was the right coice of word)

Posted: Tue May 24, 2005 4:34 pm
by Todd_Z

Code: Select all

$line = trim( $line );

Posted: Tue May 24, 2005 4:37 pm
by jolinar
Thanks Todd_Z, works now :D