sonny Posted March 26, 2010 Share Posted March 26, 2010 I am converting perl scripts over to php does anyone know how to convert this code below over to php code? { my $n = 0; open (FH, "<", 'count.txt') or die "$!"; $n = <FH>; close FH; if ($n < 10) { open (FH, ">", 'count.txt') or die "$!"; print FH ++$n; close FH; } else { print "Limit reached\n"; exit(0); } @mail('$to, $subject, $message, headers'); Thanks Sonny Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/ Share on other sites More sharing options...
beamerrox Posted March 26, 2010 Share Posted March 26, 2010 read up on fopen, fread, fwrite and fclose, fairly simple after that...sorry, not going to write a script for you Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032261 Share on other sites More sharing options...
sonny Posted March 26, 2010 Author Share Posted March 26, 2010 Does anyone know how I can delete my account on here? if there is no way, please can a admin remove me, I do not need wise a@# remarks like that, what would have been the big deal anyway. Ive seen people on here ask for 100 times more help on writing code then this. Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032266 Share on other sites More sharing options...
oni-kun Posted March 26, 2010 Share Posted March 26, 2010 Does anyone know how I can delete my account on here? if there is no way, please can a admin remove me, I do not need wise a@# remarks like that, what would have been the big deal anyway. Ive seen people on here ask for 100 times more help on writing code then this. No one will delete your account, it is wasteful. If you do not wish to recieve help from others, and have others write the code for you, look into the freelancing forum or else-sites. No one said you have to stay. If you want a wise ass remark, That code takes seconds to convert into PHP, why should you if you cannot act properly towards helpful advice? Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032268 Share on other sites More sharing options...
sonny Posted March 26, 2010 Author Share Posted March 26, 2010 What? no one will delete my account, I never read anything about signing up, was a lifetime thing? you make it sound like that was a privilege or something, there should be a delete button in profile its a commonsense and fair thing to have. You and that other guy are punk wise guys, this forum is useless because of people like you! go write yourself some code on politeness when you get some time, and share that with your bro above. Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032278 Share on other sites More sharing options...
beamerrox Posted March 26, 2010 Share Posted March 26, 2010 sorry to say 'sonny' we can't all just hold you by the hand and do all the work for you, i was rather busy with work at the time, and with your comments i scrapped what i put together for you... Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032335 Share on other sites More sharing options...
sonny Posted March 26, 2010 Author Share Posted March 26, 2010 sorry to say 'sonny' we can't all just hold you by the hand and do all the work for you, i was rather busy with work at the time, and with your comments i scrapped what i put together for you... You didn't put nothing together for me, stop it, your just trying to get the last word in, and look good, you two guys where just trying to to make a fool out of me. People like you are ruining this forum. Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032343 Share on other sites More sharing options...
shlumph Posted March 26, 2010 Share Posted March 26, 2010 Sonny, give your best effort in changing the code before asking for help Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032351 Share on other sites More sharing options...
sonny Posted March 26, 2010 Author Share Posted March 26, 2010 Sonny, give your best effort in changing the code before asking for help Ok, $n = 0; $fh = @fopen('count.txt', 'r+') or die('Error in opening file for read & write'); $n = fread($fh); if ($n < 3) { ftruncate($fh, 0); @fwrite($fh, ++$n) or die ('Unable to write to file!'); } else { print "Limit Reached\n"; } fclose($fh); This is giving me Warning: Wrong parameter count for fread() error Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032363 Share on other sites More sharing options...
jonsjava Posted March 26, 2010 Share Posted March 26, 2010 try this: <?php $n = 0; $fh = @fopen('count.txt', 'r+') or die('Error in opening file for read & write'); $n = fread($fh,filesize('count.txt')); if ($n < 3) { ftruncate($fh, 0); @fwrite($fh, ++$n) or die ('Unable to write to file!'); } else { print "Limit Reached\n"; } fclose($fh); ?> Glad to see you work your way through it! Oh, and you need to give the size of the file for it to open (length). Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032367 Share on other sites More sharing options...
sonny Posted March 26, 2010 Author Share Posted March 26, 2010 The code above is still not working right This is the reason I was asking for help my way, I need to have a 0 in the file to start Plus every time the number is updated it pushws it to the right with a space in front, something is not right with this code. I figured someone might have a fresh way to do this the whole basics behind this is so that I can have a setting for limiting emails, I am not a pro not even close, just trying but I cannot stand someone trying to make a fool out of me thats why I lost it, I don't think anyone on here would want that. Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032378 Share on other sites More sharing options...
jonsjava Posted March 26, 2010 Share Posted March 26, 2010 but I cannot stand someone trying to make a fool out of me thats why I lost it, I don't think anyone on here would want that. Guess again. We don't care if you "lose it". We're volunteers here. We don't get paid a cent for helping. If you get an attitude, there are hundreds of other people who need our help, and will show a grain of respect. Have a nice day. Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032380 Share on other sites More sharing options...
sonny Posted March 26, 2010 Author Share Posted March 26, 2010 but I cannot stand someone trying to make a fool out of me thats why I lost it, I don't think anyone on here would want that. Guess again. We don't care if you "lose it". We're volunteers here. We don't get paid a cent for helping. If you get an attitude, there are hundreds of other people who need our help, and will show a grain of respect. Have a nice day. Just think about this for a moment, why even add your 2 cents then? other then to be a wise guy, I never asked you or anone in purticular for anything, I simply posted a tread for some minor help thats all, Guess what, I guessed wrong I guess, I'll speak in your native tongue maybe it will sink in deeper. what a smart ... you are man Quote Link to comment https://forums.phpfreaks.com/topic/196607-covert-perl-log-count-code-to-php/#findComment-1032387 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.