
Simon Lloyd
Members-
Posts
26 -
Joined
-
Last visited
Never
Everything posted by Simon Lloyd
-
Fatal error Call to undefined function
Simon Lloyd replied to Simon Lloyd's topic in PHP Coding Help
Thanks guys, i used closedir($handle) and now no error, now it just shows me a list of directory contents, thanks again -
Hi all, firstly let me say im not a coder but can just about get by, i have the code below in a file (delfile.php) it's function is to delete files in the designated directory if they are over a month old, i'm running it via a cron job in cpanel and the line to run it is: php /home/xxxxxx/public_html/delfile.php When the cron runs i get this error returned in the cpanel email telling me the contents of the file and then this error underneath, what have i missed or done wron in the code below? Fatal error: Call to undefined function close() in /home/xxxxxx/public_html/delfile.php on line 33 <?php // if you not running this script in the directory // then you must add directory to the file you are // reading. $directory = '/home/xxxxxx/public_html/expupload'; $latesttime = time (); $handle = opendir ( $directory ); while ( false !== ( $file = readdir ( $handle ) ) ) { if ( $file != '.' && $file != '..' ) { $path = $directory . '/' . $file; echo $file . "<br>"; $filetime = filemtime ( $path ); echo $filetime . "<br>"; $dtime = ( $latesttime - $filetime ); if( ! is_dir ( $path ) && $dtime >= 604800 ) { unlink ( $path ); } } } close ($handle); ?> Regards, Simon
-
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
I dont know what i can show you, vbulletin has a plugin system where you choose a hook (a pre programmed location or execution point) plop in your php code but without <? at either end and your away! (providing the code works) -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Ok, well i think that i've come to the end of what i can do without really annoying you, the code i posted a couple of posts ago works great (with the negative assertions) apart from working with FUNCTION so i guess i'll remove that and live with it. I have to say hats off to you for sticking with me this far, i appreciate what you've been trying to do and am sorry that there are just some things that i can't convey very well due to lack of knowledge,but again thanks Regards, Simon -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
I simply copied it verbatim, however i removed what seemed to be an erroneous ' just before IF and the error i now get is: so i guess it needed the ' -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
I implemented it by replacing all the code for that supplied, running it last time and with the revised code gave this error i know you were expecting an error and for it to give you some clue but other than a delimiter issue i cant help you understand my issue -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
I tried that and it gave an error relating to preg_replace, didnt catch it because it was up briefly, it didnt echo the $data! -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Im on php 5.2.17, a lot of my add-ons..etc wont function in php5.3.x unfortunately, thanks for that i'll give it a try -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Ok, this works perfect but only if i remove the: Function MyTest() blah End Function The word Function makes it nuts!, any ideas? $post['message'] = preg_replace('/\\[code\\](.*)(?<!\[\/KODE\])\\[\/code\\]/siU', '[KODE]\\1[/KODE]', $post['message']); $post['message'] = preg_replace("/(?<!\[KODE\]|End\s)Sub(?<!\s\[\/KODE\])(.*)End Sub/siU", '[KODE]Sub \\1 End Sub[/KODE]', $post['message']); $post['message'] = preg_replace("/(?<!\[KODE\]|End\s)Function(?<!\s\[\/KODE\])(.*)End Function/siU", '[KODE]Function \\1 End Function[/KODE]', $post['message']); So how can we change the last preg_replace to ignore the word FUNCTION as a command word? Regards, Simon -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Hi would it help to have test forum access (although you'd have to replace [ code ] tags there) or would it help to have the bbcode.php?, to be honest with you all that needs checking is, is there already a [KODE] tag there before SUB or FUNCTION if yes skip END SUB or END FUNCTION and look for next SUB or FUNCTION do the check again if no [KODE] tag is present then add [KODE]just before it, find the next END SUB or END FUNCTION and after it add [/KODE]. Like i said above the one where i do each seperately works but too well as it doubles or tripples up depending on how many instances of code there are in the post being made, thats why i tried adding the negative assertion code to one of them to try it but couldn't get the syntax correct. I appreciate this is probably frustrating to you and really appreciate you sticking with it. Regards, Simon -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Sorry $MyString should read differently $pattern1 = "/(?<![KODE])Sub\s/"; $pattern2 = "/(?![/KODE])End Sub/"; $pattern3 = "/Function\s/"; $pattern4 = "/End Function/"; $replace1 = "[KODE]Sub "; $replace2 = "End Sub[/KODE]"; $replace3 = "[KODE]Function "; $replace4 = "End Function[/KODE]"; $post['message']= preg_replace($pattern1, $replace1, $post['message']); $post['message']= preg_replace($pattern2, $replace2, $post['message']); $post['message']= preg_replace($pattern3, $replace3, $post['message']); $post['message']= preg_replace($pattern4, $replace4, $post['message']); $post['message']= preg_replace('/\\[code\\](.*)\\[\/code\\]/siU', '[KODE]\\1[/KODE]', $post['message']); I tried adding the negative assertion to check the beginnig and end, i got an error back "..Unknown qualifier "K"...", so i tried to escape it like this \\[KODE\\]..etc but still an error, im just shooting in the dark as i don't have the foggiest what im doing. Regards, Simon -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Would it be easier to go back to pattern1 = "/Sub\s/"; $pattern2 = "/End Sub/"; $pattern3 = "/Function\s/"; $pattern4 = "/End Function/"; $replace1 = "[KODE]Sub "; $replace2 = "End Sub[/KODE]"; $replace3 = "[KODE]Function "; $replace4 = "End Function[/KODE]"; $MyString= preg_replace($pattern1, $replace1, $post['message']); $MyString= preg_replace($pattern2, $replace2, $post['message']); $MyString= preg_replace($pattern3, $replace3, $post['message']); $MyString= preg_replace($pattern4, $replace4, $post['message']); $MyString= preg_replace('/\\[code\\](.*)\\[\/code\\]/siU', '[KODE]\\1[/KODE]', $post['message']); and maybe add /(?<![KODE])Sub/ will only match "Sub" if it is not preceded by "[KODE]". I found that on the net but i don't know how to implement it for each of the expressions and i especially have no idea how to implement it for following "End Sub"...etc Regards, Simon -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Ok changed the entire for each like this //foreach( $matches as $match ) { //if( !empty($match[1]) ) // check if [kode] was found //continue; //$parsed[] = array( //'name' => $match[3], //'arguments' => $match[4], //'body' => trim($match[5]) //); //} foreach( $matches as $match ) { if( !empty($match[1]) ) // check if [kode] was found continue; echo "[KODE]$match[2] $match[3]($match[4]) $match[5] End $match[2][/KODE]\n"; } There wasn't a replacement if no tags existed and no echo and there wasn't the echo if tags existed, i even replaced echo with print but nothing appeared? -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
It didnt make any replacements at all, why would that be do you think? in the previous preg_replace it worked too well and doubled sometimes tripled up so im wondering why your latest solution didnt replace anything? even if i tested with only one section of data to look at Sub Test() If This = "" Then Msgbox "This is that" End If End Sub it didnt replace anything in that string, did i need the print command uncommented? i thought that may have just been to show the results on screen? Regards, Simon P.S When i said i'm no young pup i meant you cant teach an old dog new tricks well not quickly anyway! -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Lol, i understand you we're trying to teach me (and im no young pup!) and vbulletin has a plugin area designed specifically for php where you just add the php code without the start and end <?. I dont understand REGEX or the scenarios of where we'd use look forward, look back, look around...etc, so i have to admit i was looking for a solution which i could then later try and decipher as to why it works and what it's doing. Still, ido appreciate everything you've done so far, thanks Regards, Simon -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Thanks for replying again, i used the code $expr = '/(\[KODE\])?\s*(sub|function)\s+([a-z0-9]+)\(([a-z0-9 ]*)\)(.*?)end \2/si'; preg_match_all( $expr, $post['message'], $matches, PREG_SET_ORDER ); $parsed = array(); foreach( $matches as $match ) { if( !empty($match[1]) ) // check if [kode] was found continue; $parsed[] = array( 'name' => $match[3], 'arguments' => $match[4], 'body' => trim($match[5]) ); } //print_r( $parsed ); I replaced $data with $post['message'] because thats the source of the data, i had to comment out the //print_r($parsed); as it was giving an error "headers already sent" but thats just down to the way vbulletin works, even with that fault top left of the screen it displayed "Array()" and no replacements were made, even after commenting out the the print command and running it no replacemnets were made. Am i using it wrong? did i need something from the Output code? -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Just a short note, i've tried using the boundary limit "/\bSub (*)\b/".....etc but still get the tags doubling or tripling up! -
Help with either str_replace or preg_replace
Simon Lloyd replied to Simon Lloyd's topic in Regex Help
Hey thanks for the reply, there will never be a Sub anytext(parameters) without End Sub and they are never nested within each other, however they may appear after each other like Sub Test() 'some code End Sub Sub Test2(MyTest by Val) 'some code End Sub Function TestFunc() 'some code End Function Function TestFunc2(Rng As Range) 'some code End Function the code should skip replacing Sub or Function if the [KODE] tag is present before it the same with End Sub or End Function [/KODE] tag appearing after them should cause it to be skipped from replacing, there would only be one strange anomaly and that is the word Function may appear within a sub like Sub Mytest() 'some code Function...etc End Sub so if the word function appears between Sub... and End Sub then it should not be replaced, it never happens the other way around like Sub appearing in the Function routine. Lol, have i made any sense? ask me anything else you need, i appreciate anything you can help with -
Hi all, this is my first post here AND i'm a novice so please be gentle. I own a forum and my members can post code (much like here) but i used a modified version of CODE tags, some of my members are either new to forums or just dont use the tags, what i'd like is, via php, to check to see if my KODE tags are in place if they are do nothing, if CODE tags are in place replace them with the KODE tags, if neither KODE or Code tags are in place look for Sub anytext(parameters) where anytext can be anything (there's always a space between Sub and anytext) and parameters may or may not be present so those parenthesis could simply look like () . When found replace Sub anytext(parameters) for [KODE]Sub anytext(parameters) then find End Sub and replace with End Sub[KODE] The only other anomalies would be the word Sub could appear as Function I can replace CODE tags if they exist, but cannot do the rest, so it would be great if it was all done in one go, i've heard that str_replace is quicker than preg_replace which of course would be preferrable, here's my effort at replacing the tags one way but it doesn't work. $pattern[0] = "Sub "; $pattern[1] = "End Sub"; $replace[0] = "[KODE]Sub\s"; $replace[1] = "End\sSub\[\/KODE\]"; $mystring = preg_replace($pattern, $replace, $mystring); The spaces are intentional, but i didnt know if i should have the whitespace character \s in the patterns. Update: This works to a fashion, however it doesn't check if any tags already exist and doubles up, not good! $pattern1 = "/Sub\s/"; $pattern2 = "/End Sub/"; $pattern3 = "/Function\s/"; $pattern4 = "/End Function/"; $replace1 = "[KODE]Sub "; $replace2 = "End Sub[/KODE]"; $replace3 = "[KODE]Function "; $replace4 = "End Function[/KODE]"; $MyString= preg_replace($pattern1, $replace1, $post['message']); $MyString= preg_replace($pattern2, $replace2, $post['message']); $MyString= preg_replace($pattern3, $replace3, $post['message']); $MyString= preg_replace($pattern4, $replace4, $post['message']); $MyString= preg_replace('/\\[code\\](.*)\\[\/code\\]/siU', '[KODE]\\1[/KODE]', $post['message']); I'm sure this can be combined and made more efficient! Regards, Simon P.S I should mention im using PHP5.2.17 Update 2:I have wrapped the whole thing in this if (strpos($post['message'],'/[KODE]/') !== true AND strpos($post['message'],'/[/KODE]/') !== true ) { //All the preg_replace code } but now the first replacement for "Sub " doesn't seem to take place?
-
How to change the way code tags # work?
Simon Lloyd replied to Simon Lloyd's topic in PHP Coding Help
There's nothing out of the box, it is a custom thing and i don't suppose i will get it done for $50. Anyway, thanks for your help and advice regards, Simon -
How to change the way code tags # work?
Simon Lloyd replied to Simon Lloyd's topic in PHP Coding Help
I didn't see it as a link as the colouration here kind of obscures it, or at leasst it does on my monitor, i'm just checking it out now, thanks, will post back! I can't even register for Bespin via IE as its not supported (pop up message at bespin as IE does not support Canvas), so i guess that means that my users will not benefit from it if using IE to browse or post to my site, so i guess i need another way I'm not saying you need to use all of bespin, but there might be parts of it you can hack at. This really isn't something that is going to be easily done. Realistically, your users should be posting well formatted code in the first place. What happens here if people post unformatted code is they usually just get ignored. Thanks again for the replies, i'm not a coder by any stretch of the imagination so hacking would be more like decimating I understand what you say about unformatted code, but we accept code posted from both newbies and old hands, not everyone was taught the same way, many have never been taught and are feeling their way, so, one of the great ways to teach them is for them to always see the code "beautified", i have to say thats how i started and now indent my code as i should. Again, thanks for the reply. Regards, Simon -
How to change the way code tags # work?
Simon Lloyd replied to Simon Lloyd's topic in PHP Coding Help
I didn't see it as a link as the colouration here kind of obscures it, or at leasst it does on my monitor, i'm just checking it out now, thanks, will post back! I can't even register for Bespin via IE as its not supported (pop up message at bespin as IE does not support Canvas), so i guess that means that my users will not benefit from it if using IE to browse or post to my site, so i guess i need another way -
How to change the way code tags # work?
Simon Lloyd replied to Simon Lloyd's topic in PHP Coding Help
I didn't see it as a link as the colouration here kind of obscures it, or at leasst it does on my monitor, i'm just checking it out now, thanks, will post back! -
How to change the way code tags # work?
Simon Lloyd replied to Simon Lloyd's topic in PHP Coding Help
Hi all, any further help or suggestions with this?, i'm willing to pay a little to get this done if it helps -
How to change the way code tags # work?
Simon Lloyd replied to Simon Lloyd's topic in PHP Coding Help
Hi guys thanks for the replies, in VBA the keywords shouldn't be present in a string so no need to search strings, the keywords however may appear between quotes " and should remain black and as typed. The modification i have on my board at the moment strips all the line breaks so although it looks ok on screen if a user copies and pastes it, it becomes a very long one liner that makes no sense at all. You are correct in assuming i want the indenting and outdenting when the relevant keywords are found, i also need to have any keyword found replaced for the exact keyword in my list, so i guess there's an issue checking the case of the text, i also need the keywords to be BLUE and any text found after ' to be green but doesn't need indenting...etc Its a convention for VBA to indent it for easy reading and comprehension, there is an indenter out there for use with VB6 and VBA but they can only be used in the applications themselves or a windows based machine but my server isn't. Any futher help is much appreciated. Regards, SImon