LavishPHPFREAK Posted March 22, 2007 Share Posted March 22, 2007 Hi guys, Im a newbie php freak and I am just stomped on this issue that im having. I have this file that has 2 lines in it. Heres how the files looks. file: fbddata.lbn line1:uncle1234562 line2: As you can see, on line 2 there is actually no data but the file still seems to have a 2 lines. But when I pull the info from the file using the "include" or "require" command it just pulls the 1st line of data. BUT..when I try to use the "include" or "require" php commend within a HTML link code like this.... <a herf="www.mysite.com/Lavishphpfreak/<?php include("fbddata.lbn" ?>/ilovephp.php>LINK</a> it gives me a link that this... http://www.mysite.com/Lavishphpfreak/uncle1234562<br />/ilovephp.php now did you notice the <br /> code that was added to the link. I have figured out that its doing this because of the blank line 2 thats in the fbddata.lbn im trying to pull the data from. Of course the easy way to fix this would be to just go into the file and delete the blank like 2 but i can't do this because i dont have permission to edit the file. Its created using "root". So does anyone know of a php code that will just pull the 1st line of data from within a file. I can't use mysql cause this is NOT in a database..and plus I haven't advanced to databases yet. hehehe thanks alot in advance. Lavish P.S. I tried to be as detailed as possible so forgive me for sounding a little bit lost. Link to comment https://forums.phpfreaks.com/topic/43856-how-to-pull-1-line-of-data-from-a-file-no-mysql/ Share on other sites More sharing options...
rcorlew Posted March 22, 2007 Share Posted March 22, 2007 have you tried escaping the end of your php include like this <a herf="www.mysite.com/Lavishphpfreak/<?php include("fbddata.lbn" ?>\/ilovephp.php>LINK[/url] php will add white space if endings are not escaped properly Link to comment https://forums.phpfreaks.com/topic/43856-how-to-pull-1-line-of-data-from-a-file-no-mysql/#findComment-212913 Share on other sites More sharing options...
LavishPHPFREAK Posted March 22, 2007 Author Share Posted March 22, 2007 have you tried escaping the end of your php include like this <a herf="www.mysite.com/Lavishphpfreak/<?php include("fbddata.lbn" ?>\/ilovephp.php>LINK[/url] php will add white space if endings are not escaped properly Hi Rcorlew thanks for your help. But I have tried that and it just ads the (\) after the <br /> that it adds. Do you know how I can stop it from adding this code to the end? <br /> Link to comment https://forums.phpfreaks.com/topic/43856-how-to-pull-1-line-of-data-from-a-file-no-mysql/#findComment-212924 Share on other sites More sharing options...
rcorlew Posted March 22, 2007 Share Posted March 22, 2007 have you tried ltrim() yet. You can also try rtrim(), just sub it for ltrim() Something like this: <?php $file = include"fbddata.lbn"; $str = "$file"; $clean = ltrim($str, "<br />"); //or if it is another return that you may not be aware of try this $clean = ltrim($str); echo "<a href=\"www.mysite.com/Lavishphpfreak/$clean/ilovephp.php\">LINK</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/43856-how-to-pull-1-line-of-data-from-a-file-no-mysql/#findComment-212949 Share on other sites More sharing options...
LavishPHPFREAK Posted March 22, 2007 Author Share Posted March 22, 2007 have you tried ltrim() yet. You can also try rtrim(), just sub it for ltrim() Something like this: <?php $file = include"fbddata.lbn"; $str = "$file"; $clean = ltrim($str, "<br />"); //or if it is another return that you may not be aware of try this $clean = ltrim($str); echo "<a href=\"www.mysite.com/Lavishphpfreak/$clean/ilovephp.php\">LINK</a>"; ?> thanks once agian there for all your help. But i have tried using that code with rtrim and ltrim but that doesn't seem to work eather. It still ads the <br /> code and with this new code ltrim and rtrim..it actually ads a number (1) along with the <br /> code. :'( now since the file fbddata.lbn is kind of like a flat file im guessing...is there a way to just pull from the 1st line of the file. Even though within the fbdata.lbn there are 2 lines..its just that the 2nd line is blank and im guessing that why the <br /> is added to the end. Link to comment https://forums.phpfreaks.com/topic/43856-how-to-pull-1-line-of-data-from-a-file-no-mysql/#findComment-213057 Share on other sites More sharing options...
rcorlew Posted March 23, 2007 Share Posted March 23, 2007 I goofed, I was on my way to work when I realized what you should do, here goes one last time, <?php $myFile = "fbddata.lbn"; $fh = fopen($myFile, 'r'); $contents = fread($fh, filesize($myFile)); $clean = rtrim($contents); //or if it is another return that you may are aware of try this whith whatever html code the break is //$clean = rtrim($contents, "<br />"); echo "<a href=\"www.mysite.com/Lavishphpfreak/$clean/ilovephp.php\">LINK</a>"; Link to comment https://forums.phpfreaks.com/topic/43856-how-to-pull-1-line-of-data-from-a-file-no-mysql/#findComment-213282 Share on other sites More sharing options...
AndyB Posted March 23, 2007 Share Posted March 23, 2007 <?php $lines = file("fbddata.lbn"); // reads the file into an array $firstline = $lines[0]; // zeroth element is the first in the array ... ?> Link to comment https://forums.phpfreaks.com/topic/43856-how-to-pull-1-line-of-data-from-a-file-no-mysql/#findComment-213391 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.