Reputation: 373
I'm new to php so please bear with me here.
Its a rough example but lets say I have a file (which obviously does't work :), say 1.php
, there I have
<?php
function links1($l1, $l2){echo "<a href='". $l1 ."'><img src='". $l2 ."'/></a>";}
$ext_file = '2.php';
$v1 = fopen($ext_file, 'r');
$data = fread($v1, filesize($ext_file));
//i assume some piece of code has to go here?? Or maybe i need a new approach ...
?>
where I'm trying to basically read 2.php where I have
links1("gg1", "1.jpg");
links1("gg2", "2.jpg");
etc...
so that when I open 1.php I would see 1.jpg 2.jpg etc etc... How to do that?
And if its possible, how should I modify the code that I could only put
gg1 1.jpg
gg2 2.jpg
gg3 3.jpg
gg4 4.jpg
....
and it would still work?
Thank you guys for help!
Upvotes: 0
Views: 1521
Reputation: 19380
It is possible...
$data = file_get_contents('2.php');
$data = explode("\n", $data);
foreach($data as $string){
list($l1, $l2) = explode(' ', $string);
links1($l1, $l2);
}
If your line end of line is set to Windows and not UNIX they use "\r\n"
...
Upvotes: 1
Reputation: 84140
You can simply include 2.php inside 1.php.
<?php
function links1($l1, $l2){echo "<a href='". $l1 ."'><img src='". $l2 ."'/></a>";}
include "2.php";
?>
2.php should look like:
<?php
links1("gg1", "1.jpg");
links1("gg2", "2.jpg");
There are 4 different types of include:
Upvotes: 1