Lamez Posted December 12, 2008 Share Posted December 12, 2008 I am parsing a text file, and so far so good, but I need help on this next bit. I have a file like so [title]Page Title[/title] [h1]Main Topic[/h1] Rest of my content here. is there a way to read in only the [title][/title] part as a variable, such a $title. Then read in the rest of the file contents. Here is my current code: <?php include ("style/xtra/bbcode.php"); $title = fopen("pages/home.txt", "r"); include ("style/xtra/head.php"); $file = "pages/home.txt"; $f = fopen($file, "r"); while ( $line = fgets($f, 4000) ) { $htmltext = bb2html($line); echo $htmltext; } include ("style/xtra/foot.php"); ?> Link to comment https://forums.phpfreaks.com/topic/136610-solved-text-files-and-php/ Share on other sites More sharing options...
.josh Posted December 12, 2008 Share Posted December 12, 2008 if it's the first line in the file, do an fgets 1 time before the while loop. Link to comment https://forums.phpfreaks.com/topic/136610-solved-text-files-and-php/#findComment-713316 Share on other sites More sharing options...
Lamez Posted December 12, 2008 Author Share Posted December 12, 2008 like fgets("path/filename.txt"); Link to comment https://forums.phpfreaks.com/topic/136610-solved-text-files-and-php/#findComment-713320 Share on other sites More sharing options...
.josh Posted December 12, 2008 Share Posted December 12, 2008 no, like what you have in your while loop: $title = fgets($f, 4000); while($line = fgets($f, 4000)) { ... } Link to comment https://forums.phpfreaks.com/topic/136610-solved-text-files-and-php/#findComment-713325 Share on other sites More sharing options...
Lamez Posted December 12, 2008 Author Share Posted December 12, 2008 thank you so much, that did it Link to comment https://forums.phpfreaks.com/topic/136610-solved-text-files-and-php/#findComment-713335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.