/    Sign up×
Community /Pin to ProfileBookmark

Dynamic Friend Pik_n_Link_Text!

Please Help!

Me and my friends are developing a simple web page and we need a little help.

We have..
links/links.txt and blabber/blabber.text each with lines of text where one line equeal ones thing we need to use.
Also we got a folder named pic containing pictures names pic1.jpg, pic2.jpg etc

What we are looking for is php code to decide on a simple number and then to pull that picture and the relevant lines from both text files. The line from the links file needs to create a <a>link</a>

So if you load the page and PHP picked 5 (for example!) we’d display pic5.jpg with line 5 of blabber.txt and a link created from line 5 of urls in links.txt

Does that make sense? Will somebody help please!

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@SarahBabauthorMay 01.2008 — No help from anybody.

Did I say something wrong? :o
Copy linkTweet thisAlerts:
@NogDogMay 01.2008 — The [url=http://www.php.net/file]file[/url]() function will read a file into an array, with each line of the file being a separate array element. You could then select which line you want by specifying an array index which is 1 less than the desired number (since the array starts its numbering at 0).
Copy linkTweet thisAlerts:
@MrCoderMay 01.2008 — [code=php]
<?php
$id = (int)$_GET["id"];
?>
<img src="pic<?php echo $id; ?>.jpg">

<?php
// Depending on you OS try "rn" instead of "n" if you have extra line breaks.
$blabber = explode("n", file_get_contents("blabber.txt"));
$links = explode("n", file_get_contents("links.txt"));

// May need to +/- the $id value here depending on your line number vs image number values.
?>
<a href="<?php echo $links[$id]; ?>"><?php echo $blabber[$id]; ?></a>
[/code]
Copy linkTweet thisAlerts:
@NogDogMay 01.2008 — [code=php]
<?php
$id = (int)$_GET["id"];
?>
<img src="pic<?php echo $id; ?>.jpg">

<?php
// Depending on you OS try "rn" instead of "n" if you have extra line breaks.
$blabber = explode("n", file_get_contents("blabber.txt"));
$links = explode("n", file_get_contents("links.txt"));

// May need to +/- the $id value here depending on your line number vs image number values.
?>
<a href="<?php echo $links[$id]; ?>"><?php echo $blabber[$id]; ?></a>
[/code]
[/QUOTE]

Since file() does the same thing as explode("n", file_get_contents()), you might as well just use file() to save a little complexity and most likely save a millisecond or two. Although it does leave the newlines intact at the end of each field, so you'd probably have to trim() whichever value you select; so maybe it's six of one and a half dozen of the other?
Copy linkTweet thisAlerts:
@SarahBabauthorMay 03.2008 — Thanks so much for the assistance!

I came up with a slight modification so the page only needed to be included/required once.

For this I used the [B]rand[/B] function.

Also added a text file in an Iframe (to load individual text files like news1.txt, news2.txt) although may delete this later. ?


So the final code...

[code=php]

<?php
$id = rand(1, 149);
?>
<img src="pics/pic<?php echo $id; ?>.jpg">
<br>

<?php
// Depending on you OS try "rn" instead of "n" if you have extra line breaks.
$blabber = explode("n", file_get_contents("blabber.txt"));
$links = explode("n", file_get_contents("links.txt"));

// May need to +/- the $id value here depending on your line number vs image number values.
?>
<?php echo $blabber[$id]; ?><br>
<iframe src="news/news<?php echo $id; ?>.txt" width="200px" height="400px" frameborder="2" scrolling="yes"></iframe>
<br>
<a href="http://<?php echo $links[$id]; ?>"><?php echo $links[$id]; ?></a>
<br>

[/code]


Once again thanks for the help!
×

Success!

Help @SarahBab spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...