PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 13th, 2013, 10:00 AM
gametwodne gametwodne is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 gametwodne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m
Reputation Power: 0
Print_r array not quite like I want

Hello everybody,

I have a php script that generates an array with filenames. I want to echo/print these filenames, but when I do so, nor only the filenames get printed, but also the following:

array( [0]=> [1]=> etc. )

I am a total newbie in php, and I am allready glad that I converted the orignal script into something using an array, but I want just the filenames not the other stuff.

What should I change? Thanks a lot in advance, I;m probably doing something very stupid here...

here is the code:



PHP Code:
<?php
$directory 
'images/slideshow/';     
try {        
    
// Styling for images    
    
echo "<div id=\"myslides\">";    
    
    
    foreach ( new 
DirectoryIterator($directory) as $item ) {            
        if (
$item->isFile()) {
                
        
                    
$path "\"".$directory.$item."\"";
                    
$imgpath "<img src=".$path.">";
                    
$imagearray[] = $imgpath;
    }}
        
sort($imagearray);
        
print_r($imagearray);
            
        
//print_r($imagearray);
    
    
echo "</div>";
}    
catch(
Exception $e) {
    echo 
'No images found for this slideshow.<br />';    
}
?>

Reply With Quote
  #2  
Old January 13th, 2013, 10:02 AM
gametwodne gametwodne is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 gametwodne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m
Reputation Power: 0
to be clear, this is what the code above shows:

Array
(
[0] => <img src="images/slideshow/PICT1023.jpg">
[1] => <img src="images/slideshow/PICT1024.jpg">
[2] => <img src="images/slideshow/PICT1025.jpg">
[3] => <img src="images/slideshow/PICT1026.jpg">
[4] => <img src="images/slideshow/PICT1027.jpg">
[5] => <img src="images/slideshow/PICT1028.jpg">
[6] => <img src="images/slideshow/PICT1029.jpg">
[7] => <img src="images/slideshow/PICT1030.jpg">
[8] => <img src="images/slideshow/PICT1031.jpg">
[9] => <img src="images/slideshow/PICT1032.jpg">
[10] => <img src="images/slideshow/PICT1033.jpg">
[11] => <img src="images/slideshow/PICT1034.jpg">
[12] => <img src="images/slideshow/PICT1035.jpg">
[13] => <img src="images/slideshow/PICT1036.jpg">
[14] => <img src="images/slideshow/PICT1037.jpg">
[15] => <img src="images/slideshow/PICT1038.jpg">
)

and I want just the image tags, not the word array and the () [] => stuff surrounding it ...

Reply With Quote
  #3  
Old January 13th, 2013, 10:21 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,858 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 16 h 34 m 5 sec
Reputation Power: 813
Hi,

you should get used to the PHP manual. It clearly says that print_r() is a debugging function, which is used to analyze the content of a variable.

What you want is something completely different. You want to generate an HTML list from an array. There is no "magical function" for this. You have to actually loop through the array and generate a <ul> or <ol> -- or if clean markup doesn't matter, simply end each name with a <br />.

Reply With Quote
  #4  
Old January 13th, 2013, 10:33 AM
gametwodne gametwodne is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 gametwodne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m
Reputation Power: 0
Allright, that explains ...
I found a lot of threads where print-r was suggested, and never any mentioning of that being a function to debug..
I will try to make a loop with my two day php knowledge .. if anyone has suggestions on how to, I'd gladly hear about it
Thanks
!

Reply With Quote
  #5  
Old January 13th, 2013, 11:18 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,858 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 16 h 34 m 5 sec
Reputation Power: 813
Quote:
Originally Posted by gametwodne
I found a lot of threads where print-r was suggested, and never any mentioning of that being a function to debug..


Yes. Much of the code you'll find on the Internet is plain nonsense and sometimes even dangerous, so it's really important to understand the PHP manual and use it for first-hand information. PHP is kind of infamous for bad code.

I mean, as long as you're just playing around on your local computer, you don't need to write perfect code (and you can't, of course). But as soon as you want to, say, query a database and actually put the code online, you need to check the manual and not just rely on stuff you found somewhere.



Quote:
Originally Posted by gametwodne
I will try to make a loop with my two day php knowledge .. if anyone has suggestions on how to, I'd gladly hear about it


Well, just do what you already do in your other "foreach" loop. It's the exact same logic, only with different HTML elements.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Print_r array not quite like I want

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap