homepage Welcome to WebmasterWorld Guest from 54.204.217.249
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Could some one take a look at this.
An abridged cry for help...
capulet_x




msg:4164351
 4:33 pm on Jul 4, 2010 (gmt 0)

Could some one take a look at this and let me know what I'm doing wrong?

$file_handle = fopen("movieinfo.txt", "rb");

while (!feof($file_handle) ) {

$line_of_text = fgets($file_handle);
$parts = explode('=', $line_of_text);

echo "<div id='linkbox'><img src=" . $parts[0] . " width='150' height='auto' /><a href=" . $parts[1] . ">". $parts[2] ."</a></div></br>";
}

fclose($file_handle);

 

Matthew1980




msg:4164357
 5:02 pm on Jul 4, 2010 (gmt 0)

Hi there capulet_x,

What are you getting on the screen when you run this script? What does the page source say? What is the format of the text in the file you are reading from?

When developing always use the error_reporting(); function ie: error_reporting(E_ALL); pop that on to see if there are any error's being flagged up.

The echo "<div>"; looks a bit suspicious to me, I think there may be something wrong with the concatenations somewhere..

For ease of use I would do it like this:-

$file_handle = fopen("movieinfo.txt", "rb");

while (!feof($file_handle) ) {

$line_of_text = fgets($file_handle);
$parts = explode('=', $line_of_text);
//break out of php here
?>
<div id="linkbox"><img src="<?php echo $parts[0];?>" width="150" height="auto" />
<a href="<?php echo $parts[1]; ?>"><?php echo $parts[2];?></a>
</div>
</br>
<?php
//break back in to close the loop
}

fclose($file_handle);


Doing it that way negates the need for tooth picking your way through an echo'd block, and makes for easier html editing too.. Just a thought for you there ;)

Though if you absolutely need that format, this would work:-

$file_handle = fopen("movieinfo.txt", "rb");
while (!feof($file_handle) ) {

$line_of_text = fgets($file_handle);
$parts = explode('=', $line_of_text);
//note the toothpicks there, you need to escape the double quotes
echo "<div id=\"linkbox\"><img src=\"".$parts[0]."\" width=\"150\" height=\"auto\" /><a href=\"".$parts[1]."\">".$parts[2]."</a></div></br>";
}


I just tried this on my local server so I know it's functional :) I just didn't know the format of your text file, so I guessed - but it seemed to do what you want it to.

Have fun with the rest of the project..

Cheers,
MRb

Readie




msg:4164359
 5:24 pm on Jul 4, 2010 (gmt 0)

$file_handle = fopen("movieinfo.txt", "rb");

I can't find any mention of "rb" on the fopen page on php.net...

[uk.php.net...]

'r', 'r+', 'w', 'w+', 'a', 'a+', 'x', 'x+'
Are the only ones specified as allowed.

[edit]

Doh, read a bit further down.

you can also use 'b' to force binary mode, which will not translate your data.

They really shouldn't bury something like that in a wall of text :P

Matthew1980




msg:4164361
 5:43 pm on Jul 4, 2010 (gmt 0)

Hi all,

Readie: I didn't comment on that for that reason, but I thought exactly the same thing - I only use 'r' (but generally depends on the context of the project), but yes, they could have made that point a little more obvious ;)

Cheers,
MRb

dreamcatcher




msg:4164611
 9:09 am on Jul 5, 2010 (gmt 0)

Could some one take a look at this and let me know what I'm doing wrong?


What exactly is the issue capulet_x?

dc

sonjay




msg:4164661
 11:47 am on Jul 5, 2010 (gmt 0)

The concatenation within the href tag looks bad, too. <a href=" . $parts[1] . ">". $parts[2] ."</a> should be <a href="' . $parts[1] . '">"'. $parts[2] .'"</a>

And if more than one <div> is popped out in the loop, they shouldn't all be id='linkbox', since id is only allowed to be used once on a page.

But without capulet telling us what's going wrong, we can really only take WAGs in the dark.

capulet_x




msg:4166279
 4:38 am on Jul 8, 2010 (gmt 0)

I'm so sorry to respond so late. I thought that I would receive a notification when people posted to this topic. Thank you everyone for your time and responses to this.

My text file (movieinfo.txt) is formatted like the example below:

image_source_for_poster
some_movie_name
[www....] youtube_link.com?v=5aDlBO25gEA

image_source_for_poster
some_movie_name
[www....] youtube_link.com?v=5aDlBO25gEA

image_source_for_poster
some_movie_name
[www....] youtube_link.com?v=5aDlBO25gEA

( etc.)

What I am trying to do is read a group of three lines into an array, plug them in as variables into HTML, and then repeat the process with the next three lines, and so on and so on until the end of the text file is reached. I've tried a few different scripts but will either get just the first three lines as an output or if I'm actually able to get variables to plug into the html it breaks up the text lines and thus makes the link nonfunctioning. I keep feeling like this should be a simple function but I just can't seem to grasp it and the tutorials and post that I have found only address reading of the text file into an array but not outputting it into a specific format.
Anyway, I thought I'd reach out for some assistance. BTW, I'm not completely set on the text format I have above. I would be just as content with the following format:

image_source_for_poster, some_movie_name, [www....] youtube_link.com?v=5aDlBO25gEA

image_source_for_poster, some_movie_name, [www....] youtube_link.com?v=5aDlBO25gEA

image_source_for_poster, some_movie_name, [www....] youtube_link.com?v=5aDlBO25gEA

This is an example of the code result my messed up script is generating:

<div id='linkbox'><img src=C.L.A.S.S, [youtube.com...] width='150' height='auto' /><a href=5aDlBO25gEA,1.jpg
></a></div></br><div id='linkbox'><img src=INFESTATION, [youtube.com...] width='150' height='auto' /><a href=cpDBIWiy-sg, 2.jpg
></a></div></br><div id='linkbox'><img src=CREEPSHOW RAW, [youtube.com...] width='150' height='auto' /><a href=XVASIYPXmpk, 3.jpg
></a></div></br><div id='linkbox'><img src=POE, [youtube.com...] width='150' height='auto' /><a href=evY00_5SYCE,4.jpg
></a></div></br><div id='linkbox'><img src=ME & YOU AND EVERYONE WE KNOW, [google.com,...] 5.jpg
width='150' height='auto' /><a href=></a></div></br><div id='linkbox'><img src=MY BIG FAT INDEPENDENT MOVIE, [youtube.com...] width='150' height='auto' /><a href=fvipnU9IjzM,
></a></div></br><div id='linkbox'><img src=6.jpg
width='150' height='auto' /><a href=></a></div></br><div id='linkbox'><img src=
width='150' height='auto' /><a href=></a></div></br><div id='linkbox'><img src= width='150' height='auto' /><a href=></a></div></br>

You can tell upon close examination that the URLs and everything else is not inserting correctly.
Thanks for taking a look at this post. Any help or solution would be greatly appreciated.


-R-

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved