regluar expression help
Posted: Mon Aug 02, 2004 5:49 pm
I'm try to pull out the song title and artist from billboard top 100 type of list. Instead of going through the songs manually, I'm trying to strip the junk with php. I've been messing with preg_replace for some time now and have only had partial success.
Here's the format of the text I'm grabbing:
8 3 22 Burn, Usher
LaFace | ALBUM CUT | Zomba 1
9 7 21 The Reason, Hoobastank
Island | ALBUM CUT | IDJMG 2
The "odd" lines have 3 sets of numbers, then the title, then artist. I've been able to get this part stripped of the junk with preg_replace with this code:
This is working, but haven't tested thoroughly. My problem is getting the "even" lines out. Don't need that information altogether. I know I can just go through the the array I've created and remove them that way. But, I think a replacement statement would be quicker (and I'd like to learn more of this). The even lines have 3 sets of characters separated with the "|" character.
Here's my non-working code:
Any help is appreciated. Any links to good sample/tutorial sites would be nice as well. I wasn't able to view the samples on php.net, but will try the site again later.
Here's the format of the text I'm grabbing:
8 3 22 Burn, Usher
LaFace | ALBUM CUT | Zomba 1
9 7 21 The Reason, Hoobastank
Island | ALBUM CUT | IDJMG 2
The "odd" lines have 3 sets of numbers, then the title, then artist. I've been able to get this part stripped of the junk with preg_replace with this code:
Code: Select all
$SongList = explode("\n", $SongList);
$SongList = preg_replace('/^[0-9]* [0-9]* [0-9]* /', '', $SongList);Here's my non-working code:
Code: Select all
$SongList = preg_replace('/^[\w]* | [\w]* | [\w]*\n/', '', $SongList);