Jump to content

[SOLVED] What am I doing wrong?


Superian

Recommended Posts

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

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
}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.