Superian Posted August 9, 2009 Share Posted August 9, 2009 I am trying to write a script that will search for the period(.) in the string below and print everything that follows the period to the screen inside a "list tags". There will multiple tracks that will be needed to print to the screen. <?php $str = " 01. Plies - Chef (3:28) 02. Lil Wayne - U-Stream Freestyle (1:51) "; if(preg_match("/./i", $str)){ for ($i = 0; $i < count($str); $i++) { print "<li>".$str[$i]."</li>"; } } else { print " No Match"; } ?> Link to comment https://forums.phpfreaks.com/topic/169486-solved-what-am-i-doing-wrong/ Share on other sites More sharing options...
Bricktop Posted August 9, 2009 Share Posted August 9, 2009 Hi Superian, I would stick all the track listings into an array and then apply the string replace on a foreach loop. Something like: //This is the array containing the track information $trackisting = array( 01. Plies - Chef (3:28) 02. Lil Wayne - U-Stream Freestyle (1:51) ); //This is the function which will grab anything after the . and return it function trackname($string) { $file = $string; $i = strrpos($file,'.'); $trackname = substr($file,$i+1); return $trackname; } foreach($tracklisting as $track) { $trackoutput = trackname($track); echo $trackoutput } Link to comment https://forums.phpfreaks.com/topic/169486-solved-what-am-i-doing-wrong/#findComment-894228 Share on other sites More sharing options...
Superian Posted August 9, 2009 Author Share Posted August 9, 2009 Thanks! Link to comment https://forums.phpfreaks.com/topic/169486-solved-what-am-i-doing-wrong/#findComment-894262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.