Need help trimming text

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
User avatar
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Need help trimming text

Post 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)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

what are your line delimeters?

most likely a quick str_replace() shoud help
User avatar
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Post by jolinar »

a newline (not sure if delimiter was the right coice of word)
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Code: Select all

$line = trim( $line );
User avatar
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Post by jolinar »

Thanks Todd_Z, works now :D
Post Reply