Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP escaping containing divs.

Featured Replies

Hi guys, I have this script to echo out files in a directory for fancybox, I'm getting a strange result here on this page (rest of the site is not done using php; it has been tediously coded).

<?php 
  
// settings 
$base = "../images/alb";
$thumbs = "thumbs"; 
  
$files = scandir($base); 
unset($files[0], $files[1]); 
unset($files[array_search('.DS_Store', $files)]); 
unset($files[array_search('thumbs', $files)]);

$chunk = array_chunk($files, 10000);

foreach($chunk as $i => $filearray)
{
    
    foreach ($filearray as $file)
    {
        echo "
		
		<a class=\"fancybox\" rel=\"group\" href=\"$base/$file\"><img src=\"$base/$thumbs/$file\" alt=\"\"/></a>	
    	
		</div>";
	}
}
			?>
            

The first few pics seem to escape the containing divs, then it's fine. I thought it may be the if else statement, which was originally set to 10 files then do something different, I've changed that now to 10,000 so it cannot be that any more as there are only about twenty pics in each directory.

Hi guys, I have this script to echo out files in a directory for fancybox, I'm getting a strange result here on this page (rest of the site is not done using php; it has been tediously coded).

<?php 
  
// settings 
$base = "../images/alb";
$thumbs = "thumbs"; 
  
$files = scandir($base); 
unset($files[0], $files[1]); 
unset($files[array_search('.DS_Store', $files)]); 
unset($files[array_search('thumbs', $files)]);

$chunk = array_chunk($files, 10000);

foreach($chunk as $i => $filearray)
{
    
    foreach ($filearray as $file)
    {
        echo "
		
		<a class=\"fancybox\" rel=\"group\" href=\"$base/$file\"><img src=\"$base/$thumbs/$file\" alt=\"\"/></a>	
    	
		</div>";
	}
}
			?>
            

The first few pics seem to escape the containing divs, then it's fine. I thought it may be the if else statement, which was originally set to 10 files then do something different, I've changed that now to 10,000 so it cannot be that any more as there are only about twenty pics in each directory.

Idk if your aware but your missing an opening div inside your foreach loop just before

<a class=\"fancybox\" 

you only have the closing div

Edited by webdesigner93

Thanks Webdesigner, problem solved.

 

I'm out of my depth with this, I'm just trying to learn Javascript in my spare time, hopefully I can get to this level one day.

 

Massive thanks again.

Well it's not really you failing to be at a certain level it's just you simply forgot the opening div this can happen in plain old html without php as well :) Glad you got it sorted

Also to clean up your code some you could just try this

while (false !== ($file = readdir("pathtodirectory"))) {
     echo "
        <div>
        <a class=\"fancybox\" rel=\"group\" href=\"$base/$file\"><img src=\"$base/$thumbs/$file\" alt=\"\"/></a>    
    
        </div>";
      }

not exactly tested but should work

Edited by webdesigner93

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.