One of my client gave me a huge file which contain thousands of web urls, he want that into a html file having html (< a) tags with those site addresses as links.

eg: the input file contain
1. thecoderin.blogspot.com < http://thecoderin.blogspot.com/>
2. keltrondays.blogspot.com < http://keltrondays.blogspot.com/>
3. sahabm.blogspot.com < http://sahabm.blogspot.com/>
4. linuxlight.blogspot.com < http://linuxlight.blogspot.com>

the php code for convert this into format is given below:


<?

$file_to_read = "lines.txt";
$file_to_write = "output.txt";


$fh = fopen("$file_to_read", "r");
$i = 1;
while ($line = fgets($fh)) {
$row[$i] = $line;
$i++;
}
fclose($fh);



$fh = fopen($file_to_write, 'w') or die("can't open file");

$a = 1;
$max = count($row);

while ($a <= $max) {

$var[$a] = explode(" ",$row[$a]);

$data[$a] = "<a href='http://".$var[$a][1]."'>".$var[$a][1]."</a>\n";

echo $data[$a];

/*
fwrite($fh, $data[$a]);
*/



$a++;
}

#print_r($row);
?>

Category : , | Read More...... edit post

0 Response to "text to link - php"

Post a Comment

Followers

FeedCount

Latest Posts

thecoderinc

Subscribe Now