View Full Version : php loop problem
lindm
08-27-2007, 04:42 PM
Is it possible to execute a return function a certain times based on a variable containing a number. I don't want echo or anything so. This is my code that doesn't work:
function board($number) {for ($num=1; $num<=10; $num++ )
{
return "xx";
} }
In short. The above should return, $number of times...but doesn't per definition...any solutions?
The reason I use return and not echo is becuase the above code is part of a variable containing html code to be written to a file...
boogyman
08-27-2007, 05:45 PM
what you posted by itself is fine, but you say its part of something else...
please post more of your code so we can determine where the error is occuring.
lindm
08-27-2007, 07:49 PM
Oki here is a stripped version of the phpscript:
<?php
$file = fopen("formsaved.html", "w") or exit("Unable to open file!");
function board($number) {for ($num=1; $num<=10; $num++ )
{
return "test";
} }
$stringData =
'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form" name="form" method="post" action="writeform.php">
<table width="610" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">'.board(5).'</td>
</tr>
</table>
</form>
</body>
</html>
'
;
fwrite($file, $stringData);
fclose($file);
header("Location: formsaved.html");
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.