Jump to content

adambeazley

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

adambeazley's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. never mind I figured it out. The code was right, but I had a setting wrong in my CMS.
  2. Hello, I have been having a hell of a time trying to figure out this preg_replace function. Here is the deal: I have a CMS and the {thumbnail} variable will output something like: <img src="http://www.mysite.com/images/image.jpg" alt="some descriptions" class="rimage"> I need to use the {thumbnail} variable and strip out the image url out of the image src code. This is what i have so far, but it is not working: <?php echo preg_replace('/.*src=([\'"])((??!\1).)*)\1.*/si','$2','{thumbnail}'); ?> any ideas?
  3. honestly I dont know how to populate a multidimensional array. i am using a code I found on the net to list the folders and have tried to make a multidimensional array, but its all new to me. My php experience is pretty basic, so just single layer arrays are new to me. Here is the code i am currently using: <?php function getDirectoryListing($dirname, $sortorder = "a", $show_subdirs = 1, $show_subdirfiles = 0, $exts = "all", $ext_save = 1) { // This function will return an array with filenames based on the criteria you can set in the variables // @sortorder : a for ascending (the standard) or d for descending (you can use the "r" for reverse as well, works the same) // @show_subdirs : 0 for NO, 1 for YES - meaning it will show the names of subdirectories if there are any // Logically subdirnames will not be checked for the required extentions // @show_subdirfiles : 0 for NO, 1 for YES - meaning it will show files from the subdirs // Files from subdirs will be prefixed with the subdir name and checked for the required extentions. // @exts can be either a string or an array, if not passed to the function, then the default will be a check for common image files // If exts is set to "all" then all extentions are allowed // @ext_save : 1 for YES, 0 for NO - meaning it will filter out system files or not (such as .htaccess) if (!$exts || empty($exts) || $exts == "") { $exts = array("jpg", "gif", "jpeg", "png", "doc", "xls", "pdf", "tif"); } if ($handle = opendir($dirname)) { $filelist = array(); while (false !== ($file = readdir($handle))) { // Filter out higher directory references if ($file != "." && $file != "..") { // Only look at directories or files, filter out symbolic links if ( filetype ($dirname."/".$file) != "link") { // If it's a file, check against valid extentions and add to the list if ( filetype ($dirname."/".$file) == "file" ) { if (checkFileExtention($file, $exts, $ext_save)) { $filelist[] = $file; } } // If it's a directory and either subdirs should be listed or files from subdirs add relevant names to the list else if ( filetype ($dirname."/".$file) == "dir" && ($show_subdirs == 1 || $show_subdirfiles == 1)) { if ($show_subdirs == 1) { $filelist[] = $file; } if ($show_subdirfiles == 1) { $subdirname = $file; $subdirfilelist = getDirectoryListing($dirname."/".$subdirname."/", $sortorder, $show_subdirs, $show_subdirfiles, $exts, $ext_save); for ($i = 0 ; $i < count($subdirfilelist) ; $i++) { $subdirfilelist[$i] = $subdirname."/".$subdirfilelist[$i]; } $filelist = array_merge($filelist, $subdirfilelist); } } } } } closedir($handle); // Sort the results if (count($filelist) > 1) { natcasesort($filelist); if ($sortorder == "d" || $sortorder == "r" ) { $filelist = array_reverse($filelist, TRUE); } } return $filelist; } else { return false; } } function checkFileExtention($filename, $exts, $ext_save = 1) { $passed = FALSE; if ($ext_save == 1) { if (preg_match("/^\./", $filename)) { return $passed; } } if ($exts == "all") { $passed = TRUE; return $passed; } if (is_string($exts)) { if (eregi("\.". $exts ."$", $filename)) { $passed = TRUE; return $passed; } } else if (is_array($exts)) { foreach ($exts as $theExt) { if (eregi("\.". $theExt ."$", $filename)) { $passed = TRUE; return $passed; } } } return $passed; } ?> Any ideas on how to edit this to make it a multidimensional array? Thanks
  4. so i have a function that returns a list of all of the files and directories, sub directories and sub directory files into an array, but I am having a little trouble formatting the output. Here is the arrays output using print_r: 0 -> AIA DOCS 1 -> AIA DOCS/IPD_Guide_2007.pdf 2 -> ENERGY 3 -> ENERGY/AEDG_K12.pdf 4 -> ENERGY/AEDG_SmallOfficeBuildings.pdf 5 -> MANAGEMENT 6 -> MANAGEMENT/Article_ Influence_ Connect...pdf The goal here is to have a list of all of our company resources, but instead of just a running list like you see above, I would like to have the list organized into expanding folders. so you would essentially see a list of sub directories and when you click on the sub directory, it expands and shows the files within. - AIA DOCS to + AIA DOCS --IPD_Guide_2007.pdf --file2.pdf --file3.pdf --etc.. So how can I take the single layer array and format it this way?
  5. Thanks again Sasa! that worked great, give me the same answer but so much less code. @DarkWater your equation is partially right P = 5000(1 + .05)^t will give you the total that was spent that year (t). As I mentioned in the question this is a compounding interest equation, so if you want to get how much was spent over 5 years this is the equation (mathematically): P = 5000 + 5000(1 + .05) + 5000(1 + .05)^2 + 5000(1 + .05)^3 + 5000(1 + .05)^4 1st year = 5000 (not counting inflation) 2nd year = 5000 * 1.05 3rd year = 5000(1.05)^2 4th year = 5000(1.05)^3 5th year = 5000(1.05)^4 Anyway, Im sure you already know this stuff, but just in case someone is searching forums in need of an answer this might help. Peace guys and thanks allot for the help!!!
  6. I have a calculation that is working, but it is so long and I am just wondering if there is a better way. Basically, the calculation take a yearly bill and a given inflation rate and calculates how much is spent over 5, 15 and 25 year periods. Here is my code: $inflrate = 1.05; //5% inflation //calculate yearly bill $yearlybill = $avg_bill * 12; //total estimated yearly cost $cost5 = $yearlybill + $yearlybill * $inflrate + $yearlybill * pow($inflrate,2) + $yearlybill * pow($inflrate,3) + $yearlybill * pow($inflrate,4); $cost15 = $yearlybill + $yearlybill * $inflrate + $yearlybill * pow($inflrate,2) + $yearlybill * pow($inflrate,3) + $yearlybill * pow($inflrate,4) + $yearlybill * pow($inflrate,5) + $yearlybill * pow($inflrate,6) + $yearlybill * pow($inflrate,7) + $yearlybill * pow($inflrate, + $yearlybill * pow($inflrate,9) + $yearlybill * pow($inflrate,10) + $yearlybill * pow($inflrate,11) + $yearlybill * pow($inflrate,12) + $yearlybill * pow($inflrate,13) + $yearlybill * pow($inflrate,14); $cost25 = $yearlybill + $yearlybill * $inflrate + $yearlybill * pow($inflrate,2) + $yearlybill * pow($inflrate,3) + $yearlybill * pow($inflrate,4) + $yearlybill * pow($inflrate,5) + $yearlybill * pow($inflrate,6) + $yearlybill * pow($inflrate,7) + $yearlybill * pow($inflrate, + $yearlybill * pow($inflrate,9) + $yearlybill * pow($inflrate,10) + $yearlybill * pow($inflrate,11) + $yearlybill * pow($inflrate,12) + $yearlybill * pow($inflrate,13) + $yearlybill * pow($inflrate,14) + $yearlybill * pow($inflrate,15) + $yearlybill * pow($inflrate,16) + $yearlybill * pow($inflrate,17) + $yearlybill * pow($inflrate,18) + $yearlybill * pow($inflrate,19) + $yearlybill * pow($inflrate,20) + $yearlybill * pow($inflrate,21) + $yearlybill * pow($inflrate,22) + $yearlybill * pow($inflrate,23) + $yearlybill * pow($inflrate,24); So basically $cost5 would return the total amount the person would pay in 5 years with the same inflation rate (which would compound every year). So, my question is, is there some function that i dont know about that would cut this code down to a single line? I want to get the total cost for 5, 10, 15, 20 and 25 years, but i dont want 10 pages of repeating code like this. Also, if there is any way I could have a function where i could simply input the number of years and get a result, that would be ideal. Thanks
  7. wow, thanks that worked great. I really appreciate you taking the time to write this out for me. Ive looked at the log function before, but Im still not really sure how it works. Woudl you mind explaining the math behind the log function?
  8. Hey guys, I am having trouble figuring out how to do this math without 500 lines of code. Basically i am coding a little calculator that will calculate the average savings and payback that people can expect by installing a radiant barrier(energy efficiency product) in their homes. Here is what I am doing so far: I get their average monthly utility bill and make it a yearly figure (x * 12)- $yearlybill Then i grab the utility inflation rate for their state from my database - $inflrate Now i can calculate the total amount spent on utility bills over 5 years: $cost5 = $yearlybill + $yearlybill * $inflrate + $yearlybill * pow($inflrate,2) + $yearlybill * pow($inflrate,3) + $yearlybill * pow($inflrate,4); ---How can i streamline the above code? (yearly_bill x num%^incremental power) I would like to maybe have a while statement or a function which would return the total savings each year. Im thinking something like: while (sum of ($yearlybill * pow($inflrate, ++i)) < $costofproduct){ start counting then when it is > $cost of product print a result. Sorry just thinking out loud (brain farting). I want to build on that code can basically figure out the amount of time it would take for the savings to pay for the product. In other words, lets say the product is $300 and the average monthly bill is $100. the yearly bill is 1200 for year 1 * 17% savings on energy = $204 in savings for year 1. In year two with 10% inflation the total utility bills would be 1200 * 1.10 = $1320, then with the same 17% savings on energy = $224.40 in savings for year 2, for a total savings of $428.40 over that two year period. Now because the savings are more than the cost of the product, i can return/echo something like - your will pay for this product in energy savings in under 2 years. I hope I am being clear about what i am trying to do. I know how to do this, but its take many lines off code and many if statements and was wondering if there is a more advanced way to do it. Thanks in advance for your help.
  9. Whats up everyone, Ive always used include (relative/path.php); and I am in a situation where I have a CMS (content management System) and I need to access my include directory globally. in other words I cant do ../../relative/path.php. Is it cool to use the full server path like below? include (/var/www/html/my/path/to/files.php); Are there security implications of doing this? Also can I have my includes directory above the public directory? If /var/www/html/ is my public directory, can I have my includes directory in /var/www/includes ? thanks Adam
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.