[Wolves] quick php question

Luke Redpath luke at birmingham.lastfield.co.uk
Fri Aug 19 18:53:44 BST 2005


Hi,

As Jono said, you might have a quicker response in future posting to a
dedicated PHP list, but I can help you so I'll give you a quick
solution.

I'm assuming you have a source file that looks like this:

--source.txt--
http://www.google.com
http://www.amazon.co.uk
http://www.bbc.co.uk
Etc...
--source.txt--

Just a simple list of URLs. Now, I'm not a big fan of procedural
programming, but instead of giving you a full-blown OOP solution, I'll
just give you some simple functions that do the job. Be sure to include
link_reader_functions.php into the script you are working on.

--link_reader_functions.php--
function auto_link($url) {
	return "<a href=\"$url\">$url</a>";
}

function link_list($source) {
	$output = '<ul>';
	foreach(file($source) as $line_num => $url) {
		$output .= '<li>'.auto_link(rtrim($line)).'</li>';
	}
	$output .= '</ul>';
	return $output;
}
--link_reader_functions.php--

Simply use it like this:

--example.php--
<?php
require 'link_reader_functions.php';
?>

<h1>My Links</h1>

<?php echo link_list('source.txt') ?>
--example.php--

That will render a nice unordered html list of links, which you can then
format as required using CSS. I've not tested it but it should work.
E-mail me off-list if you have a problem with the script.

HTH

Luke

-----Original Message-----
From: Re-LoaD [mailto:reload at brum2600.net] 
Sent: 19 August 2005 16:01
To: Wolverhampton Linux User Group
Subject: [Wolves] quick php question

Hello World,

quick question for all you php guru's :)

I need to read a pain text file that contains some url's and display the
file on a web page containing clickable links were it finds a url in the
text file.

I can got it sort of working but there must be an easier way than
splitting and array by /[space]

thanks as always

Re-



---
Hand Tested Antivirus: Outbound message clean.
Tested on: 19/08/2005 16:00:55





_______________________________________________
Wolves LUG mailing list
Homepage: http://www.wolveslug.org.uk/
Mailing list: Wolves at mailman.lug.org.uk
Mailing list home: http://mailman.lug.org.uk/mailman/listinfo/wolves

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/wolves/attachments/20050819/bf1c9be4/attachment.html


More information about the Wolves mailing list