...

View Full Version : Breaks in dynamic HTML causing problems



dan-dan
04-14-2012, 02:09 PM
I actually had a thread posted in the javascript frameworks forum, but after a lot more testing I think this is a PHP issue.

I'm using PHP to dynamically create a photo gallery. It calls the file name and description from the DB then creates the containing div.

I'm also using the jQuery plugin 'fancybox', which I originally thought was causing the problem.

I eventually realised the problem was breaks in my anchors. Though the thumbs show fine, the images won't open in fancybox!
Below is taken from my source, the top entry being one I 'fixed' manually, the bottom being one of the dynamic enteries:



<div class="thumb">
<a href="http://www.jerseymet.gov.je/images/foglifting.jpg" rel="gallery_image" title="Fog lifting at Jersey Airport">

<img src="http://www.jerseymet.gov.je/images/foglifting.jpg" alt="Fog lifting at Jersey Airport" />

<p title="Fog lifting at Jersey Airport">Fog lifting at Jersey Airport</p>

</a></div>
<div class="thumb"> <a href="http://www.jerseymet.gov.je/images/foglifting.jpg
" rel="gallery_image" title="Fog lifting at Jersey Airport
"><img src="http://www.jerseymet.gov.je/images/foglifting.jpg
" alt="Fog lifting at Jersey Airport
" /> <p title="Fog lifting at Jersey Airport
">Fog lifting at Jersey Airport
</p> </a> </div>


And below is my PHP code including the manual one.


<div class="thumb">
<a href="http://www.jerseymet.gov.je/images/foglifting.jpg" rel="gallery_image" title="Fog lifting at Jersey Airport">
<img src="http://www.jerseymet.gov.je/images/foglifting.jpg" alt="Fog lifting at Jersey Airport" />

<p title="Fog lifting at Jersey Airport">Fog lifting at Jersey Airport</p>

</a></div>
<?php

$result = get_row("gallery", "*");

while ($row = mysql_fetch_assoc($result)) {

$image = $ImagePath.$row['path'];
$des = $row['description'];

echo '<div class="thumb">

<a href="'.$image.'" rel="gallery_image" title="'.$des.'">
<img src="'.$image.'" alt="'.$des.'" />
<p title="'.$des.'">'.$des.'</p>
</a>

</div>';
}
?>


I don't see where I've gone wrong. I've never had any issues like this before.
Is the breaking up of tags like that normal of PHP? Seems strange.

Thanks.

dan-dan
04-14-2012, 02:28 PM
OK, I got it working, but I don't like the solution.

The entire issue was the the closing quotation of the anchor breaking onto the next line.
So I removed them, and although it now works on all browsers, it's not correct HTML.

I also tried adding the quotations here:

$image = '"'.$ImagePath.$row['path'].'"';

That didn't do anything either (as expected).

Anyone have any ideas on how to fix this properly, retaining the proper HTML.



<a href='.$image.' rel="gallery_image" title="'.$des.'">

NancyJ
04-14-2012, 05:33 PM
$image = trim($image)

Or you could find out where there are linebreaks in your image names

dan-dan
04-14-2012, 06:21 PM
That's the thing, there are no breaks within the filenames whatsoever, Ive already checked that.

However, trim did fix it properly.

Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum