I don't know if I missed something. The function is not printing at all. $contents_of_page = file_get_contents('../bible1.html'); preg_match_all("#<td.*>(.+)</td#Ui", $contents_of_page, $tdInnerHTML); $totaltds = count($tdInnerHTML[1]); print_r($tdInnerHTML[1]);//prints all TD contents /********************************************************************************/ function recValues(){ $tdValues = array(); $tdValues = ""; for($j = 0; $j < $totaltds; $j++){ if($j % 10 != 0){ $tdValues .= "'".$tdInnerHTML[1][$j]; if($j < 9){ $tdValues .= "', "; }else{ $tdValues .= "'"; } } } return $tdValues; } echo "<span style='font-weight: bold;'>hi".recValues()."hi</span><br />\n"; PHP:
$totaltds, and $tdInnerHTML do not exist in the scope of recValues()... make them global. Or pass them as parameter.
Ok so I moved some things in the function. But another problem appears.The last $tdValues .= "'".$tdInnerHTML[1][$j]; shouldn't have ,' that follows it. I'm avoiding the multiples of 10 if($j % 10 != 0){ function recValues(){ $contents_of_page = file_get_contents('../bible1.html'); preg_match_all("#<td.*>(.+)</td#Ui", $contents_of_page, $tdInnerHTML); $totaltds = count($tdInnerHTML[1]); print_r($tdInnerHTML[1]);//prints all TD contents $tdValues = array(); $tdValues = ""; for($j = 0; $j < $totaltds; $j++){ if($j % 10 != 0){ $tdValues .= "'".$tdInnerHTML[1][$j]; $tdValues .= "', "; if($j % 10 != 0 + 9){ $tdValues .= "'"; $tdValues .= "<br />"; } } } return $tdValues; } echo "<span style='font-weight: bold;'>".recValues()."</span><br />\n"; PHP: So it's this part of the code that has to be fixed. I want to insert at every (multiple of 10) + 9. In other words 19, 29, 39... if($j % 10 != 0 + 9){ $tdValues .= "'"; $tdValues .= "<br />"; } } PHP: