crueheads Posted March 3, 2010 Share Posted March 3, 2010 Newbie here, and my first post after banging my head on Google for several hours... And all I can find are scripts that rip a single random line out of a text file, not do the handling I need done... Anyway here goes, I need a php script that will read a flat text file, entries on the text file are separated by lines and then create a dynamic image using GD... The flat text file looks something like this, and new entries will be added so the list will grow but not overly large, say 30 entries max... Title Name 1 Hash 1 Name 2 Hash 2 Name 3 Hash 3 Name 4 Hash 4 What I need is for PHP to read the list, grab even numbered lines only and create an image of just the 'Name X' entries, in a single column... The width of the created image can be constant and fixed, but I'm having a hard time figuring out how to parse the entire text file, dropping odd numbered entries and generate an image 'tall' enough with all the text to it... If that makes any sense... If I have to fix the height of the generated image to a safe height I can accept that... Any help would be appreciated, and thank you in advance... BTW here is the SLOPPY, code I used to verify that my text file creation script was doing its job, this will parse the generated text file and spit out what I want, but getting the output to a generated image is stumping me... <? $file = "data.txt"; $f = fopen($file, "r"); while ( $line = fgets($f, 1000) ) { $line2 = fgets($f, 1000); $gtext = nl2br($line2); print $gtext; } ?> Link to comment https://forums.phpfreaks.com/topic/193963-dynamic-image-creation-with-gd-and-a-flat-text-file/ Share on other sites More sharing options...
inversesoft123 Posted March 3, 2010 Share Posted March 3, 2010 $fcontents = join ('', file ($_SERVER['DOCUMENT_ROOT'].'/mytextdata.txt')); $s_con = split("~",$fcontents); $data= rand(0,(count($s_con)-1)); echo $s_con[$data]; Here we are splitting data with symbl ~ mytextdata.txt should be like this Name 1 ~ Hash 1 ~ Name 2 ~ Hash 2 ~ Name 3 Link to comment https://forums.phpfreaks.com/topic/193963-dynamic-image-creation-with-gd-and-a-flat-text-file/#findComment-1020770 Share on other sites More sharing options...
crueheads Posted March 3, 2010 Author Share Posted March 3, 2010 $fcontents = join ('', file ($_SERVER['DOCUMENT_ROOT'].'/mytextdata.txt')); $s_con = split("~",$fcontents); $data= rand(0,(count($s_con)-1)); echo $s_con[$data]; I believe there is a misunderstanding I'm not interested in pulling a random line out, I want all the 'names' to be pulled out and displayed... I want the script to read a text file like this Title Name 1 Hash 1 Name 2 Hash 2 Name 3 Hash 3 and generate a dynamic image like the one attached... [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/193963-dynamic-image-creation-with-gd-and-a-flat-text-file/#findComment-1020781 Share on other sites More sharing options...
inversesoft123 Posted March 3, 2010 Share Posted March 3, 2010 Name 1 ~ Hash 1 ~ Name 2 ~ Hash 2 ~ Name 3 you can you even modify this code to get entries one by one Link to comment https://forums.phpfreaks.com/topic/193963-dynamic-image-creation-with-gd-and-a-flat-text-file/#findComment-1020784 Share on other sites More sharing options...
crueheads Posted March 3, 2010 Author Share Posted March 3, 2010 you can you even modify this code to get entries one by one Well modifying the code that makes the flat text file to include the ~ splitting entries is not a problem... That's easy enough to change... It's reading that text file and then creating the dynamic image that I'm asking for help with I'm drawing a blank... Link to comment https://forums.phpfreaks.com/topic/193963-dynamic-image-creation-with-gd-and-a-flat-text-file/#findComment-1020794 Share on other sites More sharing options...
crueheads Posted March 3, 2010 Author Share Posted March 3, 2010 OK so modifying your code, I can parse the text file, so now can some one toss me a bone on creating the dynamic image and putting it all together? <?php $fcontents = join ('', file ($_SERVER['DOCUMENT_ROOT'].'/text.txt')); $s_con = split("~",$fcontents); $total = (count($s_con)-1); $step = 0; while ($step <= $total) { echo (($s_con[$step])"\n"); $step = $step + 2; } ?> Link to comment https://forums.phpfreaks.com/topic/193963-dynamic-image-creation-with-gd-and-a-flat-text-file/#findComment-1020811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.