Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How 2 Do it? 1

Status
Not open for further replies.

dakoz

Programmer
Feb 2, 2002
74
I Am new in PHP so excuse the post if might sound very easy to solve.

i have the following situation

i have a .txt file

with the following records


My picture - Latest pic - Brand pic -

ok so far.

i want to make a php script in order to take the following and put them in a form i made.

here is the form :

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function imgchange()
{
var si = document.frm.selbox.selectedIndex;
var fname = document.frm.selbox.options[si].value
document.img.src = fname
}
//-->
</SCRIPT>


A WANT THE FOLLOWING FORM TO BE GENERATED DYMICALLY ACCORDING TO the .txt FILE CONTENT. HWO CAN I CAPTURE IN PHP THE TEXT UNTIL &quot;-&quot; AND THE URL IN ORDER TO PLACE THEM IN THIS FORM?

<CENTER>
<FORM name=&quot;frm&quot;>
<SELECT NAME=&quot;selbox&quot; size=1&quot; onchange=imgchange()>
<OPTION VALUE=&quot; picture
<OPTION VALUE=&quot; pic
<OPTION VALUE=&quot; pic
</SELECT>
</FORM>
<IMG SRC=&quot;1.gif&quot; NAME=&quot;img&quot;>
</CENTER>
</HTML>
</BODY>



THANK YOU FOR YOUR TIME
-----------------------
 
Something like
[tt]if (($fp = fopen(&quot;<filename>&quot;, &quot;r&quot;)) === FALSE)
die(&quot;Couldn't open the file.&quot;);
while (!feof($fp))
{
$line = fgets($fp);
list($text, $url) = explode(&quot;-&quot;, $line, 2);
echo &quot;<option value=\&quot;$url\&quot;>$text</option>&quot;;
}
fclose($fp);[/tt]
should do it.

See the manual for more information:

//Daniel
 
Warning: Wrong parameter count for fgets() in /var/ on line 6

Warning: Wrong parameter count for fgets() in /var/ on line 6

Warning: Wrong parameter count for fgets() in /var/ on line 6

Warning: Wrong parameter count for fgets() in /var/ on line 6

Warning: Wrong parameter count for fgets() in /var/ on line 6

Warning: Wrong parameter count for fgets() in /var/ on line 6

Warning: Wrong parameter count for fgets() in /var/ on line 6

Warning: Wrong parameter count for fgets() in /var/ on line 6


i get this



this is start.php as u suggested

<?PHP
if (($fp = fopen(&quot;./temp.txt&quot;, &quot;r&quot;)) === FALSE)
die(&quot;Couldn't open the file.&quot;);
while (!feof($fp))
{
$line = fgets($fp);
list($text, $url) = explode(&quot;-&quot;, $line, 2);
echo &quot;<option value=\&quot;$url\&quot;>$text</option>&quot;;
}
fclose($fp);

?>
 
If your version of PHP is older than 4.2.0, you would have to change
[tt] $line = fgets($fp);[/tt]
to
[tt] $line = fgets($fp, 1024);[/tt]

//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top