Skip to content

Instantly share code, notes, and snippets.

@niczak
Created February 20, 2012 23:02
Show Gist options
  • Save niczak/1872135 to your computer and use it in GitHub Desktop.
Save niczak/1872135 to your computer and use it in GitHub Desktop.
Text Parsing To Create Links
<?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