daviga404 Posted November 4, 2011 Share Posted November 4, 2011 Hi! Basically, I'm making a PHP file that lists things from a file, so if the file contained; '@-Line 1-@@-Line 2-@' it would produce <li><a href="#">Line 1</a></li><li><a href="#">Line 2</a></li>, but I want it so it changes the coding for 1 of every 2 lines. So I've came up with this code: $myFile = "list.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 100); fclose($fh); $oldtxt = array("@-", "-@"); $newtxt = array('<li><a href="#">','</a></li>'); $newData = str_replace($oldtxt, $newtxt, $theData); $array = explode("</li>", trim($newData)); $lineno = count($array); $linenofinal = $lineno - 1; for($i=1;$i<$linenofinal;$i++){ if(($i % 2)=='0'){ } } The bit that I'm stuck on is inside the if statement. How could I get it to replace for example <li> in line $i with <li class="1in2"> Thanks in advance, Daviga404 =D Quote Link to comment Share on other sites More sharing options...
RussellReal Posted November 5, 2011 Share Posted November 5, 2011 $array[$i] = str_replace('<li>','<li class="1and2">',$array[$i]); Quote Link to comment Share on other sites More sharing options...
daviga404 Posted November 6, 2011 Author Share Posted November 6, 2011 $array[$i] = str_replace('<li>','<li class="1and2">',$array[$i]); Wow. I feel stupid now >.< Thank you so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.