
John_A
Members-
Posts
70 -
Joined
-
Last visited
Everything posted by John_A
-
In it's simplest form, I have a tree hierarchy in a MySQL database where every section has both a 'sectionID' and a 'parent', both numeric values. My starting point will be an array of sectionID numbers, e.g. 2, 3, 5, 8, 13, 21, 34, 55 & 89 - but this could be much larger. From this array, I want to go back up the tree on each until a certain parent is hit, say for example 144 (which isn't guaranteed). From this I want to create two new arrays: - 1) Those sectionIDs from the original list where 144 is listed as a parent somewhere higher up the hierarchy and 2) Those where 144 doesn't feature higher up the tree The depth is unknown, but I'd know the end is reached when parent is either not set or is equal to 1 or 0. Any help would be greatly appreciated!
-
Delete files / folders in current, with exclusions
John_A replied to John_A's topic in PHP Coding Help
I did want to avoid that but I guess adding that in was easier than trying to rewrite the CleanUpCacheDirectory() function.... Needed a little tweaking but I managed to get it working...I think! -
I've got a thumbnailing script I'm using which uses phpThumb(), but as an object which means I'm having to handle my own cache. What I've got in a folder is: - [phpthumb].htaccess index.php When used, the script will create additional files / folders in here, which are cached versions of images pulled from elsewhere, so for example I might end up with: - [holidaysnaps] [phpthumb] [work-images] .htaccess dsc123467.jpg index.php lolcat.gif etc. etc. My script is at index.php and I want to add a CleanUpCacheDirectory() function to it so that it manages the cache as well. I've tried taking phpThumb's CleanUpCacheDirectory() function and modifying to suit but the first major problem is that it requires a folder to point at and deals with everything inside that, which I can't do here as that would include the phpthumb folder itself, as well as my index.php script and the .htaccess file. And for various reasons, I really don't want to add a "cache" folder in here. Ideally I'd like the same options as phpThumb, i.e.: - //$PHPTHUMB_CONFIG['cache_maxage'] = null; // never delete cached thumbnails based on last-access time $PHPTHUMB_CONFIG['cache_maxage'] = 86400 * 30; // delete cached thumbnails that haven't been accessed in more than [30 days] (value is maximum time since last access in seconds to avoid deletion) //$PHPTHUMB_CONFIG['cache_maxsize'] = null; // never delete cached thumbnails based on byte size of cache directory $PHPTHUMB_CONFIG['cache_maxsize'] = 10 * 1024 * 1024; // delete least-recently-accessed cached thumbnails when more than [10MB] of cached files are present (value is maximum bytesize of all cached files) //$PHPTHUMB_CONFIG['cache_maxfiles'] = null; // never delete cached thumbnails based on number of cached files $PHPTHUMB_CONFIG['cache_maxfiles'] = 200; // delete least-recently-accessed cached thumbnails when more than [200] cached files are present (value is maximum number of cached files to keep) With these set, I'd want to loop through all folders / files in the current folder, but excluding the phpthumb folder (and everything in it), and also ignoring the .htaccess and index.php files. If it helps, the phpThumb CleanUpCacheDirectory() function is about 1/5th of the way down here: http://phpthumb.sourceforge.net/index.php?source=phpthumb.class.php Any help would be greatly appreciated!
-
I removed the use of escapeshellcmd() in the email (I actually meant to do that before posting) and also from the exec() to make sure, and the result was the same - only the list and email parameters work
-
I just did...it didn't make any difference.
-
I've got a mailing list (uses DadaMail) which provides a perl script (subscribe_email.pl) so that I can pass subscribers to it thorugh a PHP script. Info here: http://dadamailproject.com/support/documentation-5_0_1/COOKBOOK-subscriptions.pod.html#command_line_utility___subscribe_email_pl The trouble is I can get it working when variables are passed to it via URL query strings, but when I try to hard-code variables into it it stops working. I can't see any reason for this, it's got me really confused. This works: - <?php // example usage: - // http://www.domain.com/[email protected]&title=Mr&forename=John&surname=Doe&company=None&country=UK if (isset($_GET['sendto'])) { $email = $_GET['sendto']; } if (isset($_GET['title'])) { $title = preg_replace("/[^A-Za-z ]/", "", $_GET['title']); } if (isset($_GET['forename'])) { $forename = preg_replace("/[^A-Za-z\-. ]/", "", $_GET['forename']); } if (isset($_GET['surname'])) { $surname = preg_replace("/[^A-Za-z\-. ]/", "", $_GET['surname']); } if (isset($_GET['company'])) { $company = preg_replace("/[^A-Za-z()\-.& ]/", "", $_GET['company']); $company = str_replace('&', 'and', $company); } if (isset($_GET['country'])) { $country = preg_replace("/[^A-Za-z\-.& ]/", "", $_GET['country']); $country = str_replace('&', 'and', $country); } if (isset($email)) { $exec_command = 'perl ./subscribe_email.pl --list mylist --email '. $email; if (isset($title)) $exec_command .= ' --fields title '. $title; if (isset($forename)) $exec_command .= ' --fields forename '. $forename; if (isset($surname)) $exec_command .= ' --fields surname '. $surname; if (isset($company)) $exec_command .= ' --fields company '. $company; if (isset($country)) $exec_command .= ' --fields country '. $country; exec(escapeshellcmd($exec_command)); } else { echo 'Nothing to do'; } ?> The mail address and all the parameters are passed to the subscribe_email.pl script. But, this doesn't work: - <?php $subscriber_email = '[email protected]'; $subscriber_title = 'Mr'; $subscriber_forename = 'John'; $subscriber_surname = 'Doe'; $subscriber_company = 'None'; $subscriber_country = 'UK'; if (isset($subscriber_email)) { $email = escapeshellcmd($subscriber_email); } if (isset($subscriber_title)) { $title = preg_replace("/[^A-Za-z ]/", "", $subscriber_title); } if (isset($subscriber_forename)) { $forename = preg_replace("/[^A-Za-z\-. ]/", "", $subscriber_forename); } if (isset($subscriber_surname)) { $surname = preg_replace("/[^A-Za-z\-. ]/", "", $subscriber_surname); } if (isset($subscriber_company)) { $company = preg_replace("/[^A-Za-z()\-. ]/", "", $subscriber_company); $company = str_replace('&', 'and', $company); } if (isset($subscriber_country)) { $country = preg_replace("/[^A-Za-z\-. ]/", "", $subscriber_country); $country = str_replace('&', 'and', $country); } if (isset($email)) { $exec_command = 'perl ./subscribe_email.pl --list mylist --email '. $email; if (isset($title)) $exec_command .= ' --fields title '. $title; if (isset($forename)) $exec_command .= ' --fields forename '. $forename; if (isset($surname)) $exec_command .= ' --fields surname '. $surname; if (isset($company)) $exec_command .= ' --fields company '. $company; if (isset($country)) $exec_command .= ' --fields country '. $country; exec(escapeshellcmd($exec_command)); } else { echo 'Nothing to do'; } ?> In the second example, only the list and email parameters are passed, all the others are lost (or ignored). All that's different between the two is the way the variables are inititally set, I can't for the life of me figure out why the second one isn't working . Even stranger, I tried testing with just: - <?php exec("perl ./subscribe_email.pl --list mylist --email [email protected] --fields title Mr --fields forename John--fields surname Doe --fields company None --fields country UK") ?> and this doesn't work fully either (again just the list and email parameters are passed). Unfortunately, it's the second method I need to use as it's tagged on to the end of a contact form processing script which initiates the subscription if a checkbox is left ticked...and all variables will be coming from this form script. Any help greatly appreciated!
-
Thanks, I'll give that a try and stick with it unless anyone has a more efficient method! The source is a DB from a 3rd party application, which I don't want to interfere with. I actually edited it with a JOIN but had to keep applying the edit every upgrade, this new approach is as a 'plug-in' to basically inject what I need into the existing array.
-
I have one array, called for example $MainImages : - Array ( [0] => Array ( [widgetID] => 143 [image] => image_a.jpg ) [1] => Array ( [widgetID] => 147 [image] => image_b.jpg ) [2] => Array ( [widgetID] => 73 [image] => image_c.jpg ) ) and a second array, we'll call it $widgets: - Array ( [0] => Array ( [widgetID] => 147 [seo_title] => An excellent class B Widget [name] => Widget B [categoryID] => 1 ) [1] => Array ( [widgetID] => 73 [seo_title] => An excellent class C Widget [name] => Widget C [categoryID] => 1 ) [2] => Array ( [widgetID] => 143 [seo_title] => An excellent class A Widget [name] => Widget A [categoryID] => 1 ) ) I want to merge the value from the [][image] key from the first array into a new [][image] key / value in the second, using a shared value as a reference...so the desired result array is: - Array ( [0] => Array ( [widgetID] => 147 [seo_title] => An excellent class B Widget [name] => Widget B [categoryID] => 1 [image] => image_b.jpg ) [1] => Array ( [widgetID] => 73 [seo_title] => An excellent class C Widget [name] => Widget C [categoryID] => 1 [image] => image_c.jpg ) [2] => Array ( [widgetID] => 143 [seo_title] => An excellent class A Widget [name] => Widget A [categoryID] => 1 [image] => image_a.jpg ) ) Obviously the order is different and so they need to be merged based on the widgetID values. Also, the same widgetID may be in each array more than once. I've looked at a lot of help but can't find anything to do exactly what I need....any help would be greatly appreciated!
-
Thanks again
-
Excellent, just what I needed. Thanks
-
Many thanks! What's the best way to then remove the offending -[digit] from the string (sorry, I should have included this in my original question)?
-
I've got a string which is usually abc-def-0123 but it sometimes has an additional dash and then a single digit (e.g. ghi-jkl-4567-1). It's always the same pattern and length, (three letters, a dash, three letters, a dash, 4 digits then the possibility of a dash followed by a single digit). What's the best way to test if the string ends in a dash followed by a single digit? Any help much appreciated!
-
Thanks for your help! I ended up with this which works great: - function showproductinfo($thisproduct){ echo 'Product #' . $thisproduct['product_id'] . ' is a ' . $thisproduct['colour'] . $thisproduct['title'] . ', code: ' . $thisproduct['code']; } showproductinfo($all_products[1]);
-
It's not perfect, but it works. All I'm asking is, is it better to declare the global array variable within the function, or to pass the array to the function?
-
Every time? I'm calling the function 50 times or more on the same page.
-
Thanks both for your help! I did this: - function showproductinfo($thisproduct){ global $all_products; echo 'Product #' . $thisproduct . ' is a ' . $all_products[$thisproduct]['colour'] . $all_products[$thisproduct]['title'] . ', code: ' . $all_products[$thisproduct]['code']; } showproductinfo(1); Which seems to work. Are there any downsides to this?
-
I thought this would be fairly straightforward but for some reason isn't working. I have an array built from some MySQL data: - $all_products[1] = array( "title"=>"widget", "product_code"=>"wid-123", "colour"=>"blue"); $all_products[2] = array( "title"=>"thingy", "product_code"=>"thi-345", "colour"=>"red"); This works fine when used like: - echo 'Product #1 is a ' . $all_products[1]['colour'] . $all_products[1]['title'] . ', code: ' . $all_products[1]['code']; Gives: "Product #1 is a blue widget, code: wid-123" However, if I do this: - function showproductinfo($thisproduct) { echo 'Product #' . $thisproduct . ' is a ' . $all_products[$thisproduct]['colour'] . $all_products[$thisproduct]['title'] . ', code: ' . $all_products[$thisproduct]['code']; } showproductinfo(1); It gives nothing Can I use a variable passed via a function as the array key in this way? If so, how? And if not, what's the best way to do what I, trying to do?
-
Thanks again Scot, you have been most helpful and it is much appreciated
-
That's excellent Scot, thanks a lot. It does indeed do exactly what I wanted Just a few questions:- 1) The "parent" and "child" labels I gave in my example are known values, which I admit wasn't clear by my choice of using "parent" and "child"! Would it be more efficient to use these when looking for the keys / values, rather than checking every possibiilty (it's part of a fairly large array). 2) Is it easily changed to look for "This" or "That" (or an array of strings to check for)?
-
Lets sat I have a multidimensional array. call it $my_array.... Print_r($my_array) gives: - Array ( [parent] => Array ( [child] => Array ( [0] => Array ( [itemID] => 3 [name] => This Item [lowlimit] => 50 [highlimit] => 0 ) [1] => Array ( [itemID] => 6 [name] => That Item [lowlimit] => 50 [highlimit] => 0 ) ) ) ) It's the child items I want to deal with. It won't always have both items, it may have only 1 or more. I want to look for any child item who's [name] key includes the string "This", and if found remove that whole child item (in this case $my_array -> parent -> child -> 0) and then fix the indexing again so they start at 0 and increment OK. The trouble is, I don't know where to start? Any help much appreciated!
-
Hi, I need a function to return the next x working days (Mon - Fri). So for 7 from today it would return: - Monday 8th March Tuesday 9th March Wednesday 10th March Thursday 11th March Friday 12th March Monday 15th March Tuesday 16th March But also with the ability to pass to it days to be excluded (for example Christmas / Boxing day and New Year's Day, as well as any custom public holidays). I've done something similar before but it ended up being rather long, I'm looking to keep this as short and simple as possible....any ideas?
-
You are of course correct! Shortly after my last post here I realised that what had started out as a MySQL question had turned into a PHP one, so I cross-posted at http://www.phpfreaks.com/forums/index.php/topic,273536.msg1292207.html. I marked that thread as solved, and hadn't done this one - sorry!
-
Excellent, works a treat, thanks!
-
This ouputs:- which is correct indicates that a class is stored in $instructions[0] rather than an array :-\ I have no idea what that means....or how I managed to do it that way. The question now is, is it workable as it is? I need to check if an array exists for each document type, if it does output a heading etc. then list the relevant docs....i.e. can I still loop through each array?
-
this outputs: -