PHP - Die Function To Allow Html Codes Not Stop Every Code When Initiated.
how can i use die but still continue with the html in the rest of code instead of stopping all codes from where die is initiated.
i want to die (insert into database) but then still allow the html codes below the die function to work still. \= Similar Tutorialsi need help here..i want to echo a lage code of html but it is giving me problems..i know it will hv to do with the syntax but am confused on how to go about it..below is the php code and the html codes Code: [Select] <?php include"header.php"; session_start(); if(isset($_POST['submit'])) { $log=mysql_real_escape_string($_POST['mail1']); $pas=($_POST['pass1']); if($log=='' || $pas=='') { echo "Please supply your Username(your email address) and your password"; } else { $sel="SELECT user_name,userID FROM user WHERE (user_email='$log') AND (user_password='$pas')"; $ok=mysql_query($sel) or die(mysql_error()); if(mysql_num_rows($ok)==0)echo"Wroung Username or Password used,Please try again"; else { while($row=mysql_fetch_array($ok)) { $_SESSION['userID']=$row['userID']; $_SESSION['user_name']=$row['user_name']; $_SESSION['user_date']=$row['user_date']; echo $_SESSION['user_date']=$row['user_date']; echo"this is where i want to put the html codes so that the user_name appears on the page".$_SESSION['user_name']; } } } } mysql_close(); ?>this is the html codes Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta name="Description" content="Information architecture, Web Design, Web Standards." /> <meta name="Keywords" content="your, keywords" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="Distribution" content="Global" /> <meta name="Author" content="Erwin Aligam - ealigam@gmail.com" /> <meta name="Robots" content="index,follow" /> <link rel="stylesheet" href="images/PixelGreen.css" type="text/css" /> <title>Planetafric</title> </head> <body> <!-- wrap starts here --> <div id="wrap"> <div id="header"><div id="header-content"> <h1 id="logo"><a href="index.html" title="">speak<span class="gray">out</span></a></h1> <h2 id="slogan">The Revolution is now...</h2> <!-- Menu Tabs --> <ul> <li><a href="index.html" id="current">Home</a></li> <li><a href="index.html">News</a></li> <li><a href="index.html">Downloads</a></li> <li><a href="index.html">Support</a></li> <li><a href="index.html">About</a><li> </ul> </div></div> <div class="headerphoto"></div> <!-- content-wrap starts here --> <div id="content-wrap"><div id="content"> <div id="sidebar" > <div class="sidebox"> <h1>About this Website</h1> <p>Due to the injustice we face conitnualy in this nation WE (KTECHGROUP) have decided to stamp our feet against all this ills in our country..THE TIME IS NOW ..Stand against non avalabitlty of social amenities, stand against unemployment and stand against corruption.<img src="speakout_1.png"/></p> </div> <div class="sidebox"> <h1 class="clear">Sidebar Menu</h1> <ul class="sidemenu"> <li><a href="index.html" class="top">Home</a></li> <li><a href="#TemplateInfo">Template Info</a></li> <li><a href="#SampleTags">Sample Tags</a></li> <li><a href="http://www.styleshout.com/">More Templates...</a></li> <li><a href="http://www.4templates.com/?aff=ealigam">Premium Templates</a></li> </ul> </div> <div class="sidebox"> <h1>Sponsors</h1> <ul class="sidemenu"> <li><img src="watch.jpg"/></br><h3>Longinnes wrist watch forsale at reduced price</h3></li> <li><img src="htc.jpg"/><label>4templates</label</li> <li><a href="http://store.templatemonster.com/?aff=ealigam">TemplateMonster</a></li> <li><a href="http://www.fotolia.com/partner/114283">Fotolia.com</a></li> <li><a href="http://www.text-link-ads.com/?ref=40025">Text Link Ads</a></li> </ul> </div> <div class="sidebox"> <h1>Wise Words</h1> <p>"No man can live happily who regards himself alone; who turns everything to his own advantage. You must live for others if you wish to live for yourself."</p> <p class="align-right">- Seneca</p> </div> <div class="sidebox"> <h1>Support Speakout</h1> <p>If you are interested in supporting this work and would like to contribute, you are welcome to make a small donation through the <a href="http://www.styleshout.com/">donate link</a> on this website - it will be a great help and will surely be appreciated.</p> </div> <div class="sidebox"> <h1>Search Box</h1> <form action="#" class="searchform"> <p> <input name="search_query" class="textbox" type="text" /> <input name="search" class="button" value="Search" type="submit" /> </p> </form> </div> </div> <div id="main"> <div class="post"> <a name="TemplateInfo"></a> <h1> </h1> <p>Posted by <a href="index.html">Adetoye Oni</a></p> <p><strong>A weeping Eye</strong> is a free, W3C-compliant, CSS-based website template by <strong><a href="http://www.styleshout.com/">styleshout.com</a></strong>.<p align="left"><img src="soldier_crying.jpg"/></p align> This work is distributed under thel;kmbkl;;lsjljhl;hjklghl;kk;gjhflk;jfgkl;jflhjflkhlkkjgfklk Creative Commons Attribution 2.5 License</a>, which means that you are free to use and modify it for any purpose. All I ask is that you include a link back tohjsklvjksjkskjvskdv dhlkdhlshdlkjhdslkjhkljsdhjsdhjlghdsjhjkdshgjkdhjkshdjkhdsjkhdkjsjgdgl sddjgkldsjlkgdlkshgldhsgldhlghdlshgdlhgldhlkhdlkdkhdlkgdgd djkdjklgdjklgjdslkjdlksjkldsjkldsjlkdsjklgjsldkjgkldsgdsgjdklsgjsljgl\ksdjgjldkgj;ldsk\jglkdsg <a href="http://www.styleshout.com/">my website</a> in your credits.</p> <p>For more free designs, you can visit <a href="http://www.styleshout.com/">my website</a> to see my other works.</p> <p>Good luck and I hope you find my free templates useful!</p> <p class="post-footer align-right"> <a href="index.html" class="readmore">Read more</a> <a href="index.html" class="comments"><?php if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo"Comments:".$_SESSION['views']; ?></a> <span class="date">Nov 11, 2006</span> </p> </div> <h3>Comments:</h3> <table> <tr class="row-a"> <td class="first"><?php include"header.php"; $sql="SELECT *FROM post "; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['post_date']}"."</br>"; } ?></td> <td><?php include"header.php"; $sql="SELECT *FROM post "; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['post_content']}"."</br>"; } ?></td> </tr> </table> <h3>Post your comments here</h3> <form action='reply.php'method='post'> <textarea name="comment" id="content" style="width:400px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;"></textarea> <br /> <input class="button" type="submit"name="submit"value="submit" /> </p> </form> <br /> </div> <!-- content-wrap ends here --> </div></div> <!-- footer starts here --> <div id="footer"><div id="footer-content"> <div class="col float-left"> <h1>Site Partners</h1> <ul> <li><a href="http://www.dreamhost.com/r.cgi?287326"><strong>Dreamhost</strong> - Affordable & Reliable Webhosting</a></li> <li><a href="http://www.4templates.com/?aff=ealigam"><strong>4templates</strong> - Low Cost Hi-Quality Templates</a></li> <li><a href="http://store.templatemonster.com/?aff=ealigam"><strong>TemplateMonster</strong> - Best templates on the net!</a></li> <li><a href="http://www.fotolia.com/partner/114283"><strong>Fotolia</strong> - Free stock images or from $1</a></li> <li><a href="http://www.text-link-ads.com/?ref=40025"><strong>Text Link Ads</strong> - Easiest. Money. Ever.</a></li> </ul> </div> <div class="col float-left"> <h1>Links</h1> <ul> <li><a href="http://www.openwebdesign.org/">openwebdesign.org</a></li> <li><a href="http://www.opendesigns.org/">Opendesigns.org</a></li> <li><a href="http://www.pdphoto.org/">PDPhoto.org</a></li> <li><a href="http://www.alistapart.com">Alistapart</a></li> <li><a href="http://www.cssremix.com">CSS Remix</a></li> </ul> </div> <div crrlass="col2 float-right"> <p> © copyright 2006 <strong>Ktech group</strong><br /> Programme by: <a href="index.html"><strong>Adeleye Caleb</strong></a> Valid <a href="http://jigsaw.w3.org/css-validator/check/referer"><strong>CSS</strong></a> | <a href="http://validator.w3.org/check/referer"><strong>XHTML</strong></a> </p> <ul> <li><a href="index.html"><strong>Home</strong></a></li> <li><a href="index.html"><strong>Sitemap</strong></a></li> <li><a href="index.html"><strong>RSS Feed</strong></a></li> </ul> </div> </div></div> <!-- footer ends here --> <!-- wrap ends here --> </div> </body> </html> Thanks in advance and this is the html Friends, I have a code to filter out stopwords (from text file) out of a string supplied. Seems its not filtering out the stop words. Code: [Select] <?php $CommonWords = file_get_contents('http://minimate.co.uk/stopwords.txt'); $CommonWords = explode("\n", $CommonWords); $keywords = 'This is did samle a as any ass'; $search_keywords = strtolower(trim($keywords)); $arrWords = explode(' ', $search_keywords); $arrWords = array_unique($arrWords); foreach ($arrWords as $word) { if (!in_array($word, $CommonWords) && (trim($word) != '')) { $searchWords[] = $word; } } print_r($searchWords); ?> Output is: Quote Array ( => this [1] => is [2] => did [3] => sample [4] => a [5] => as [6] => any [7] => ass ) So the output is not filtering out any words from that text file. Can someone help me with this? Cheers Natasha T <?xml-stylesheet href="/player.xsl" type="text/xsl"?> <config> <auto_start>false</auto_start> <player_skin>/test.swf</player_skin> <main_title>Test</main_title> <playlist_title>PLAYLIST</playlist_title> <time_text>TOTAL TIME</time_text> <pan_labels>L,R</pan_labels> <scroller_speed>1</scroller_speed> <scroller_marquee_content>#TRACK_NAME#</scroller_marquee_content> <repeat_is_enabled>false</repeat_is_enabled> <shuffle_is_enabled>false</shuffle_is_enabled> <default_volume>75</default_volume> <default_pan>0</default_pan> <play_list> <item>test.mp3;Test Soundtrack</item> </play_list> </config>Hi, The above code is from an XML file and I added the <?xml line of code to the XML file, but doing so causes the whole page to no longer display the track information (just blank). Is there there a way I could modify that text to try and call it another way? Thanks Edited by hexcode, 16 July 2014 - 02:52 PM. I have a habit of doing stuff like such: Code: [Select] <div class="portal_box"> <h2>Welcome to ZombieCraft's Highscores!</h2> <div class="portal_content"> Here you can sort the pros from the noobs, or just simply see whos on top of their game. The highscores will show the highsest scores, greatest to least. If you want to see a certain user's score, then just use the search button! <?php $username = $_SESSION['loggedin']; $extract_user_rank = mysql_query("SELECT rank FROM users WHERE username='$username'"); $grab = mysql_fetch_assoc($extract_user_rank); if($grab['rank'] > 0) { echo "</br><br/><a href='control_panel.php'>Admin Control Panel</a>"; } else { //return nothing } ?> </div> </div> I've been told a good bit of times that I need to stop using HTML and PHP in the same lines. How would one accomplish this? $('input#name-submit').on('click', function() { var name = $('input#name').val(); if ($.trim(name) != '') { $.post('play2.php', {name: name}, function(data) { $('div#name-data').text(data); }); } });data contains html code but when it is displayed it is displayed as text and shows the html, how can I get the html code to function properly? thanks Hello friends, if i've textarea form or even input how to prevent visitors to write html codes inside it ? thanks I have the following code in html: <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://VARIABLEVALUE.mysite.com" } //--> </script> <title>Redirecting ...</title> </head> <body onLoad="setTimeout('delayer()', 1000)"> <script type="text/javascript"> var sc_project=71304545; var sc_invisible=1; var sc_security="9c433fretre"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript> <div class="statcounter"><a title="vBulletin statistics" href="http://statcounter.com/vbulletin/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/71304545/0/9c433fretre/1/" alt="vBulletin statistics" ></a></div></noscript> </body> </html> Is a basic html webpage with a timer redirect script and a stascounter code. I know a bit about html and javascript, but almost nothing about php. My question is: How a can convert this html code into a php file, in order to send a variable value using GET Method and display this variable value inside the javascript code where says VARIABLEVALUE. Thanks in adavance for your help. I have a form that users input user name, password, and email... all writes to csv fine. My problem is I need to concatenate a a string with a variable and some html code will preserving the html when written to the csv.. I need the csv to be this username,password,email,user,category,text with http://sub.domain..com/splash/,something,something here's what i have Code: [Select] <?php if($_POST['formSubmit'] == "Submit") $varUserName = $_POST['username']; $varPW = $_POST['PW']; $varEmail = $_POST['email']; { $fs = fopen("testcsv.csv","a"); fputcsv($fs, array($varUserName,$varPW,$varEmail,"user","title",",category","some text '<a href="http://$varUserName.url.com/splash/>site.com</a>',)); fclose($fs); exit; } ?> and of course I'm getting Parse error: syntax error, unexpected T_STRING, expecting ')' on line 9 Can I combine also HTML code in PHP function? For example, can a PHP function include HTML form and the PHP code to handle this form? If yes, this will make my main code much more smaller and readable. If not, is there a way to define an "external macro" like, which allow me to replace pre-defined lines of code with short alias? I'm trying to submit html/php code through an html form and then insert it into a mysql database. I've got the following code so far (without the insert into database query), however when I submit the form I get pushed through to my 403 page. If i comment out the textarea that contains the code I am trying to submit, then it goes through fine. Any ideas? Code: [Select] <? if (isset($_POST['optone'])) {$optone=$_POST['optone']; $opttwo=$_POST['opttwo'];} if (isset($_POST['type'])) {if ($_POST['type']=='Theory') {$optone=1;} if ($_POST['type']=='Demo') {$optone=2;} $opttwo=$_POST['module'];} ?> <h3>Module administration</h3> <script> function setOptions(chosen) { var selbox = document.myform.opttwo; selbox.options.length = 0; if (chosen == " ") { selbox.options[selbox.options.length] = new Option('Please select an option first',' '); document.myform.go.disabled=true; } if (chosen == "1") { selbox.options[selbox.options.length] = new Option('Module 1','1'); selbox.options[selbox.options.length] = new Option('Module 2','2'); selbox.options[selbox.options.length] = new Option('Module 3','3'); selbox.options[selbox.options.length] = new Option('Module 4','4'); selbox.options[selbox.options.length] = new Option('Module 5','5'); selbox.options[selbox.options.length] = new Option('Module 6','6'); selbox.options[selbox.options.length] = new Option('Module 7','7'); selbox.options[selbox.options.length] = new Option('Module 8','8'); selbox.options[selbox.options.length] = new Option('Module 9','9'); selbox.options[selbox.options.length] = new Option('Module 10','10'); document.myform.go.disabled=false; } if (chosen == "2") { selbox.options[selbox.options.length] = new Option('Module 1','1'); selbox.options[selbox.options.length] = new Option('Module 2','2'); selbox.options[selbox.options.length] = new Option('Module 3','3'); selbox.options[selbox.options.length] = new Option('Module 4','4'); selbox.options[selbox.options.length] = new Option('Module 5','5'); selbox.options[selbox.options.length] = new Option('Module 6','6'); selbox.options[selbox.options.length] = new Option('Module 7','7'); selbox.options[selbox.options.length] = new Option('Module 8','8'); selbox.options[selbox.options.length] = new Option('Module 9','9'); selbox.options[selbox.options.length] = new Option('Module 10','10'); document.myform.go.disabled=false; } } </script> <br /> <center> <form name="myform" method='post'> Edit: <select id="optone" name="optone" size="1" onchange="setOptions(document.myform.optone.options[document.myform.optone.selectedIndex].value);" > <option value=" " >--Choose--</option> <option value="1" >Theory</option> <option value="2" >Demo</option> </select> <select name="opttwo" size="1"> <option value=" " selected="selected">Please select an option first</option> </select> <input type='submit' name='go' id='go' value='Go' disabled='disabled'/> </form> </center> <br /><br /> <? if (isset($opttwo)) { if ($optone==1) {$query = "SELECT info,userscompleted,last_user,enabled FROM theorydata WHERE TheoryID=".$opttwo; $typestr='Theory'; $texthelp='Code must be entered in HTML';} if ($optone==2) {$query = "SELECT info,userscompleted,last_user,enabled FROM demodata WHERE DemoID=".$opttwo; $typestr='Demo'; $texthelp='Code must be entered in PHP';} $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $query2="SELECT full_name FROM users WHERE id=".$row['last_user']; $result2 = mysql_query($query2) or die(mysql_error()); $row2 = mysql_fetch_array($result2); ?> <form method='post' > <table> <tr> <td align='center'> Type: </td> <td> <input type='text' name='type' readonly='readonly' value="<? echo $typestr; ?>" /> </td> </tr> <tr> <td align='center'> Module: </td> <td> <input type='text' name='module' readonly='readonly' value="<? echo $opttwo; ?>" /> </td> </tr> <tr> <td align='center' > Enabled? </td> <td> <select name='enabled'> <option value='yes' <? if ($row['enabled'] == '1') {echo "selected='selected'";}?> >Yes</option> <option value='no' <? if ($row['enabled'] == '0') {echo "selected='selected'";}?> >No</option> </select> </td> </tr> <tr> <td align='center'> Code: </td> <td> <center><font color='red'><? echo $texthelp; ?></font></center> <textarea name='info' rows=35 cols=80><? echo htmlentities($row['info']); ?></textarea> </td> </tr> <tr> <td align='center' > Users completed: </td> <td> <input type='text' name='userscompleted' value="<? echo $row['userscompleted']; ?>" size=4/> </td> </tr> <tr> <td align='center' > Last user: </td> <td> <input type='text' name='last_user' readonly='readonly' value="<? echo $row2['full_name']; ?>" /> </td> </tr> <tr> <td></td> <td align='center'> <input type='submit' value='Edit'/> </td> </tr> </table> </form> <? }//close isset(opttwo) ?> Hello, I just wanted to know if it was possible to get the code of a function created inside a PHP file, for example : Code: [Select] <?php function test() { $var = 0; echo $var++; } ?> I want to get the code inside the function, means : Code: [Select] <?php $string = function_get_content("test"); /* $string = "$var = 0; echo $var++;" */ ?> Is that possible in any way? I believe that I'd have to analyze the page's code :s Thanks in advance.. Checking if php function mysqli_fetch_assoc() been removed from newer php versions.
Running LAMP
Apache 2.4.7
PHP 5.5.9
MySQL 5.5.38
Running WAMPserver
Apache 2.4.9
PHP 5.5.12
MySQL 5.6.17
LAMP system, this code works fine:
<?php session_start(); $_SESSION['dbhost'] = $_POST['dbhost']; $_SESSION['dbuser'] = $_POST['dbuser']; $_SESSION['dbpass'] = $_POST['dbpass']; $_SESSION['dbname'] = $_POST['dbname']; ?> <!store variables in a session> <html> <head> <link rel="stylesheet" href="style.css"> </head> <body> <?php if (!empty($_SESSION['dbname'])) { echo "Database connection settings are saved for ".$_SESSION['dbname'].".<br>"; $con = mysqli_connect($_SESSION['dbhost'],$_SESSION['dbuser'],$_SESSION['dbpass'],$_SESSION['dbname']); if (mysqli_connect_errno()) { die("Failed to connect to your database with the saved settings.<br>"); } else { echo "Successfully connected to the database.<br><br>"; } $sql = "SELECT count(*) FROM account"; $query=mysqli_fetch_assoc(mysqli_query($con,$sql)); $count = $query["count(*)"]; if ($count == 0) { echo "Detected your account has not been configured yet: <br>"; echo 'Click <a href ="setup_account.html">here</a> to configure.<br><br>'; } else { $sql = "SELECT ircnick FROM account"; $query=mysqli_fetch_assoc(mysqli_query($con,$sql)); $user = $query["ircnick"]; echo "Found your previous saved settings: <br>"; echo 'If you want to change the settings for '.$user.' click <a href="setup_account.html">here</a>.<br>'; } } else { echo "Error saving your settings.<br>"; } ?>But on WAMP get this output: (!) Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\setup.php on line 44 Call Stack # Time Memory Function Location 1 0.0000 249936 {main}() ..\setup.php:0 2 0.0156 260184 mysqli_fetch_assoc() ..\setup.php:44 Trying to share my code with a friend who is using Windows. Edited by SmexyPantsGnome, 25 August 2014 - 09:12 PM. Hello All, I'm trying to put a lot of what I do into function calls now to make my code a bit tidier and consise. Take this simple if statement: if ($_GET['thedate'] =='') { $var = date('l, jS F, Y',time()); } else { $var = date('l, jS F, Y', strtotime($_GET['thedate'])); } How could I put this into a function and in some kind of switch statement? Thanks Hello Everyone, I do not know if I am not doing something right or if I am completely wrong. I am trying to get an error or success message depending on the out come . This is the code that I have written so far Code: [Select] <?php if (!$_POST['submit']){ $msg = "you must enter a name and message"; header("Location: {$_SERVER['URL']}testmail.php?msg=$msg"); exit; } else { $name = $_POST['name']; $message = $_POST['message']; if (strlen($name) <= 20 && $message <= 300){ if (($name == "") || ($message == "")){ $msg = " please fill in all required feilds"; header("Location: {$_SERVER['URL']}testmail.php?msg=$msg"); exit; } else { ini_set("SMTP", "smtp.greatlakes.net"); $to = "mikedmartiny@gmail.com"; $subject = "Classified Ad Submission"; $headers = "From: autostylersrv@greatlakes.net"; $headers = "MIME-Version: 1.0rn"; $headers = "Content-type: text/html"; $headers = "charset=iso-8859-1rn"; $message = "<html><body>This is a email sent from $name<br /><br />$message</body></html>"; function mail($to, $subject, $message, $headers) { $msg = "mail has been sent"; } else { $msg = "there was a error"; } } } else { $msg = "You have exceded the max lentgh"; header("Location: {$_SERVER['URL']}testmail.php?msg=$msg"); exit; } } echo "$msg"; ?> I've been making our thesis and i've been thinking if there is a function or method perhaps to get the interpreted codes(the codes you see if you get the source of the site on browsers) into another text file. something like fwrite the intertpreted code to a text file Hi, I have some code which works but when I created a function and call this same code it doesn't. The error I get is as follows: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/fhlinux010/l/languageschoolsuk.com/user/htdocs/admin/email.php on line 42 Error retrieving schools The code function CreateSchoolCheckboxes() { echo '<div style="height:400px;width:400px;font:16px/26px Georgia, Garamond, Serif;overflow:scroll;">'; $querySchools = "SELECT * FROM school"; $result = mysql_query($querySchools, $conn) or die ("Error retrieving schools ".mysql_error()); while($row = mysql_fetch_array($result)) { $schoolname = $row['name']; echo '<input type="checkbox" name="school" value="'.$schoolname.'">'; echo $schoolname . '<br>'; } echo '</div>'; } Im sure that this is probably something simple but any suggestions would be much appreciated. Thanks, Joe Hi there, can someone help to write a code for Copyright tag at the footer of the page. The format needs to be webpage start year - current year (eg © 2015-2020 ). I need to use function and parameters. The code should be as simple as possible as i am just a beginer! Thanks How can i call javascript function from php code?? (Kindly Help) As an example (idea) Code: [Select] <script language="javascript"> function divclose() { alert("I am an alert box!"); } </script> <? echo "<SCRIPT LANGUAGE='javascript'>divclose();</SCRIPT>"; ?> $dir_name="./$masterdir"; $dir = opendir($dir_name); $basename = basename($dir_name); $fileArr = array(); while ($file_name = readdir($dir)){ if (preg_match("/\.jpg$/i", $file_name)) { #Get file modification date... # $fName = "$dir_name/$file_name"; $fTime = filemtime($fName); $fileArr[$file_name] = $fTime; } } # Use arsort to get most recent first # and asort to get oldest first arsort($fileArr); ////$numberOfFiles = sizeOf($fileArr); $numberOfFiles =7; for($t=0;$t<$numberOfFiles;$t++){ $thisFile = each($fileArr); $thisName = $thisFile[0]; $thisTime = $thisFile[1]; $thisTime = date("d M y", $thisTime); echo"$masterdir/$thisName"; } closedir ($dir); this returns the latest 7 files in a dir... works fine but each is now deprecated so gives warning |