Created
February 20, 2012 23:02
-
-
Save niczak/1872135 to your computer and use it in GitHub Desktop.
Text Parsing To Create Links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define("bDEBUG", FALSE); | |
// Open file handle | |
$hfile = fopen("./links.txt", "r"); | |
// Set up some variables | |
$iCnt = 0; | |
$sOut = NULL; | |
// Walk through contents of file | |
while(!feof($hfile)) | |
{ | |
$iCnt++; | |
$sLine = fgets($hfile); | |
if(!empty($sLine)) | |
{ | |
// Show output for debugging | |
if(bDEBUG) | |
printf("%d - %s\n", $iCnt, $sLine); | |
$aLine = explode(" - ", $sLine); | |
// On the fly formatting for URL | |
$aLine[2] = str_replace("\n", "", $aLine[2]); | |
$aLine[2] = '"'.$aLine[2].'"'; | |
// Show array for debugging | |
if(bDEBUG) | |
print_r($aLine); | |
$sOut .= sprintf("<a href=%s target=\"blank\">%s</a> - %s\n\n", | |
$aLine[2], $aLine[0], $aLine[1]); | |
} | |
} | |
// Close file pointer | |
fclose($hfile); | |
$sOut = str_replace(' "', '"', $sOut); | |
echo $sOut; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment