Jump to content

[SOLVED] Loading from a test file


KFredje

Recommended Posts

Hi,

 

I started very simple with this page:

 

index.php

<html>
<head>
<?php {
$lang['t48']='Sign guestbook';
}
?>
</head>
<body>
<?php echo $lang['t48']; ?>
</body>
</html>

 

when I look in my browser it shows the right thing. But now I'd like to get all this from an extern text file, but how can I get it working?

 

tnx

Link to comment
https://forums.phpfreaks.com/topic/175680-solved-loading-from-a-test-file/
Share on other sites

the easy way to get a file's contents is

 

$myvar=file_get_contents("myfile.txt");  //$myvar will contain the string contents of the file myfile.txt

 

if you need to split the string by newlines

$myvar2=explode("\n",$myvar);  //$myvar2 will contain an array with each element being a line of text from $myvar

so this should be my page then?

 

index.php

<html>
<head>
<?php {
$myvar=file_get_contents("text.txt");
$myvar2=explode("\n",$myvar);}?>
</head>
<body>
<?php echo $lang['t48']; ?>
<?php echo $lang['homebe']; ?>
</body>
</html>

 

and this my text file: (text.txt)

 

$lang['t48']='Sign guestbook<br>';
$lang['homebe']='Welkom op onze site waar je alles vindt over ons eindwerk waaraan we het komende jaar zullen werken (2009-2010).<br>Wij (Pieter Steverlynck, Frederik Van de Velde en Ludovic Avet) zullen de windmolen gebruiken als onderwerp voor onze gip.<br>In dit eindwerk kan een stuklijst, verantwoording van materiaal, technische tekeningen, kleine testjes, sterkteleer, etc. voorkomen.<br>Na afloop zal de gip beschikbaar zijn op deze site.<br><br><img src="images/dot.png" width="100%" height="1px"><br><br><center><a href="mailto:[email protected]" style="text-decoration:none"><font color="red">[email protected]</font></a><br><br></center>';

 

if so, it don't work :S

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.