-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
need to validate the length in your script. setting maxlength to 3 isn't enough, as someone can easily edit the form to remove that restriction and submit. try casting the value as a string: $cadence = (string) $_POST['cadence'];
-
The point of OOP is to give you the ability to make your script modular (so as to make it more portable, easily interfaced with other things, etc..) and to enforce standards (like with interfaces, you can demand that classes under it have certain properties/functions defined, etc...) so that things can be easily added on. That's it. If you are making a program like a CMS or bulletin board system where you expect addons/mods to be made by yourself or others, OOP is a good thing. But if you are scripting something and don't expect it to constantly be a "work in progress" or addons/mods isn't really the nature of the script, then it's not necessary, and in fact, it is more than likely overkill. It is, of course, a little more complicated than that, because the uses of OOP extend beyond just making addons for a website. But still. I see all the time code that's made way more complicated than it needs to be, because sure, it's great that they programmed it that way, but seriously, they will never use it for something else. The main problem with OOP is that people keep saying you can do this or you can do that or it makes this or that possible but the bottom line is whether you really need those options or not. You just need to decide what your code is going to be used for, and what you realistically think it could be used for.
-
oh and if you have a local program like outlook express, you can set up multiple mail accounts to send from, using POP/IMAP services. A lot of web based email systems allow for it too (like gmail).
-
well if you format your header as this: Your Name <[email protected]> it will show up as 'Your Name' in the from (or as the to, if you put it in the 'to' portion of the header).
-
preg_match('~<td align="right">Sale Date :</td>[^<]*<td align="LEFT" colspan="2">(.*?)</td>~s',$test,$match); $date = preg_replace('~\s~','',$match[1]);
-
Well unless you are doing some kind of huge batch job, I would still opt for the preg_match method, as it is the 1-line solution. I guess it just depends on what the OP needs it.
-
oh and in case people didn't catch it..., my benchmark was multiplying microtime by 1000, so the difference is beyond negligible. Even looking at nrg_alpha's benchmark results, we're talking about .003s diff from doing 1000 calculations.
-
Yeah I know that if you're wanting to for instance to just check if a string is inside another string, to use the built-in functions instead; I figured ctype_digit and strlen by itself would be faster, but I just figured that since you were having to do multiple things: type casting, both function calls, more complex conditions, etc.. that it would all add up.
-
@MadTechie: \d allows for exponents. Better to use [0-9]{1,3} if you strictly want a 3 digit number. @nrg_alpha: Since you have to cast the subject as a string to make sure that ctype_digit works, and since you have to make conditions based on two diff functions (ctype_digit and strlen), I automatically assumed the regex would be way faster. But for shits and grins I decided to benchmark it anyways, and was surprised to see that the ctype/strlen method was actually faster... Here is my benchmark script and sample of results: <?php function pregMethod ($subject) { if (preg_match('~^[0-9]{1,3}$~', $subject)) return true; else return false; } // end pregMethod function ctypeMethod ($subject) { $subject = (string) $subject; if ((strlen($subject) > 0) && (strlen($subject) < 4)) { if (ctype_digit($subject)) return true; } else { return false; } // end strlen range } // end ctypeMethod $subject = 123; /*** test regex method ***/ for ($x = 1; $x < 11; $x++) { $time_start = microtime(true)*1000; pregMethod($subject); $time_end = microtime(true)*1000; $pregTime[$x] = $time_end - $time_start; } // end test regex method /*** test ctype method ***/ for ($x = 1; $x < 11; $x++) { $time_start = microtime(true)*1000; ctypeMethod($subject); $time_end = microtime(true)*1000; $ctypeTime[$x] = $time_end - $time_start; } // end test regex method /*** generate some stats ***/ $pregSum = array_sum($pregTime); $ctypeSum = array_sum($ctypeTime); $higher = max($pregSum, $ctypeSum); $lower = min($pregSum, $ctypeSum); $diff = $higher - $lower; $ratio = round($higher / $lower,1); /*** end generate stats ***/ /*** echo out stats ***/ echo "Benchmark test<br/>"; echo "regex vs. ctype/strlen methods<br/>"; echo "time measured in microtime*1000<br/>"; echo "<br/>"; echo "regex method: $pregSum total<br/>"; echo "ctype method: $ctypeSum total<br/>"; echo "difference of: $diff or $ratio times faster"; echo "<pre>"; print_r($pregTime); echo "</pre>"; echo "<pre>"; print_r($ctypeTime); echo "</pre>"; /*** end echo out stats ***/ ?> Benchmark test regex vs. ctype/strlen methods time measured in microtime*1000 regex method: 0.152 total ctype method: 0.0630000000001 total difference of: 0.0889999999998 or 2.4 times faster Array ( [1] => 0.087 [2] => 0.0179999999999 [3] => 0.00599999999997 [4] => 0.00600000000009 [5] => 0.00599999999997 [6] => 0.00599999999997 [7] => 0.00600000000009 [8] => 0.00499999999988 [9] => 0.00600000000009 [10] => 0.00599999999997 ) Array ( [1] => 0.013 [2] => 0.00599999999986 [3] => 0.00600000000009 [4] => 0.00599999999997 [5] => 0.00600000000009 [6] => 0.00500000000011 [7] => 0.005 [8] => 0.005 [9] => 0.005 [10] => 0.00599999999997 )
-
Would decrypting a file be considered reverse engineering? I thought reverse engineering was like, decompiling a compiled program. I think I would probably classify this as cryptanalysis.
-
I really don't see how you can possibly be proud of taking someone else's code and running it. Because that's all you did. I mean, if you wanna pat yourself on the back, by all means, go ahead. Just don't expect anybody else to be impressed. Kind of reminds me of when my mom calls me up saying she bought a computer and she's proud of herself because she got it up and running all by herself. Well whoopty doo you just plug the color coded wires in the box and flip the switch and it installs itself. I would never burst her bubble, though. She is, after all, my mom, and I love her. But you aren't my mom. POP.
-
Doesn't seem like a very bright thing to be asking after you've already done it, and bragged about it.. Interesting to...who? Especially when you admit you just c/p'ed somebody else's code...what would be interesting to know is whether you have any clue what this frankenstein code you "made" actually does.
-
What I mean is, if you're going to for example scrape a webpage using file_get_contents, you wouldn't be using quotes to assign the data to a var at all, so quoting is not an issue. But in the regex above, you are taking into consideration escaped quotes, which would be non-existent in a scraped page from file_get_contents, since the data would already be rendered. Point is, when you are trying to create a regex pattern using example data in a string, you're going to have to do some quote juggling, be it escaping, or using single/double, or whatever. But that won't really necessarily be the case/issue for where your data is coming from in production environment. Look at the OP's example string: $code = "<a href=\"test.html\">test</a>"; It would not look like that if that link was coming from a page scrape. It would not be escaped like that. But he made his regex to look for escaped quotes.
-
note that unless you are retrieving your string from some text file or something where the escape quotes will physically be there, you need to remove the escape quotes from your regex. For example, scraping a rendered webpage will not have escaped quotes in it.
-
just return the variable (or variables, as an array) and assign the function call to something. function something () { $array = array('a','b','c'); return $array; } $foobar = something(); echo $foobar[0]; // output: a echo $foobar[1]; // output: b echo $foobar[2]; // output: c
-
I'm applying for a job. How much should my salary requirement be?
.josh replied to funphp's topic in Miscellaneous
You are right, I was just going off the OP's provided number. I do agree that $65-$80k a year does seem rather high for a web dev gig, but tbh I have no idea what the cost of living in Vegas is. Cost of living is a somewhat significant factor in determining a reasonable salary. And I do agree that the OP is probably living a pipe dream if he expects to walk in there and land the job with no formal schooling/degree. Dunno what his portfolio looks like, or if he even has one. If I were the OP, and the employer did not put down $65k as an offer in their advert, I certainly wouldn't start there, given what I'm bringing to the table. But that's the key: the employer put that $65k up in their advert, so the OP would be basing negotiations off that. -
I'm applying for a job. How much should my salary requirement be?
.josh replied to funphp's topic in Miscellaneous
Well I'm all for the concept of if you can understand and do the job, who cares what it took you to get to that point. Which is the same philosophy the guys who run the business usually have. You're past experience, schooling, portfolio, etc.. blahblahblah only serves one purpose to them: verification that you aren't blowing smoke out your ass claiming you can do stuff you can't, and thereby wasting everybody's time. I'm not saying that a formal education has no value beyond that. I'm just saying that that value is subjective. Some people benefit from being in a classroom and being shown by someone else how to do something. Some people can learn just as easy from a book or website. I've seen tons and tons of people with college educations in various fields who tbh have no business doing what they are doing. And I've seen tons and tons of people without a college education in whatever field run circles around them. You really shouldn't get upset about the guy next to you, unless his pay clearly doesn't match what he's pumping out. -
see I was going to suggest that, except that that function is limited to the scope it's called from. So if I have for instance: <?php class something { public $a; private $b; protected $c; function __construct() { $this->a = 'apple'; $this->b = 'banana'; $this->c = 'coconut'; } // end __construct } // end class something $obj = new something; $x = print_r($obj, true); $y = get_object_vars($obj); echo "print_r<br/><pre>$x</pre>"; echo "get_object_vars<br/><pre>"; print_r($y); echo "</pre>"; ?> You would get the following: print_r something Object ( [a] => apple [b:private] => banana [c:protected] => coconut ) get_object_vars Array ( [a] => apple )
-
nothing but alphanumerics and forwardslashes via preg_match()? pls help
.josh replied to thepip3r's topic in Regex Help
What do you mean by "filter out"? Filter means you want to take $x and add/remove stuff to it to come out with $y. Your code looks like you are wanting to validate, not filter. As in, $x isn't this certain format in the first place, I want to do something. If you're going for the filter, you would use preg_replace. Either way, the only thing I see wrong is that you forgot to put the forward slash in your character class (the [...]) so it's not allowing for the forward slashes. Another thing that may or may not be a factor is the + makes your preg_match expect at least 1 character match, or it will fail. If you are expecting $_GET['arg'] to be empty at times, use * instead. Also, Unless you are in fact trying to filter (and therefore use preg_replace), you don't need the parenthesis ( ) they are meant for capturing results for later use. -
Don't really know why you're trying to accomplish this. If you have access to the object or whatever code might dynamically create the object, then you'd have access to that info anyways. But nonetheless, you can use print_r to dump out the properties of an object. If you set the 2nd argument to true, you can assign it to a variable instead of outputting the info. It will be stored in the assigned variable as a string of info (pretty much the same as serializing, only not as detailed). You can then scroll down to this user post on print_r's page, to get a nice little function that parses the print_r'ed string into an array.
-
I remember when I was young and wet behind the ears and I looked at systems and programs and programmers in awe, thinking they were flawless and perfect and one day when I grow up, I want to be just like them and make things just like that, and hopefully someone will find my work worthy of using. I daresay it was almost spiritual. But the more I learned what goes on under the hood and the more I grew up, the more I realized it's really not that mystical. Whatever system is in place was made by some avg. Joe just like you. (S)he just happened to be there at the time, and it's probably averagely written (could have been done better) and it's most certainly outdated (or you wouldn't be looking to replace it).
-
you would query your db and use your while loop instead of the foreach loop and check your current row's score against your previous row's score. Come on man I showed you how to pee in the toilet; you want me to unzip your fly and hold your willy too?
-
<?php /*** begin mock db select ***/ for ($x = 1; $x <=20; $x++) { $array[] = rand(100,110); } sort($array); /*** end mock db select *****/ $rank = 0; foreach($array as $score) { $r = ($score == $oldScore)? $rank : ++$rank; echo $r . " " . $score . "<br/>"; $oldScore = $score; } ?>
-
I'm applying for a job. How much should my salary requirement be?
.josh replied to funphp's topic in Miscellaneous
Haven't you ever been to a garage sale or flee market? Just like prices at those places, salaries are negotiated. They say "Okay this is what we're willing to pay". That number is what they feel probably the lowest they can get away with offering, for someone to take their offer seriously. They also have a maximum amount they are willing to pay, and they aren't going to tell you that, because then you'd just ask for that. So they want to know how much you're willing to work for. Maybe you'll do it for $45k and they'll have second thoughts about your abilities, wondering why you'd do it for so cheap (I assure you, they probably did a lot more research on 'fair salaries' than you did; especially since they know what all needs to be done for the job and you don't). Or maybe you'll accept their $65k without a fight, thinking omg I hit the jackpot, and they may or may not have 2nd thoughts about your abilities, seeing as how you jumped on it so quickly. Trick is to do the same thing as them, only in reverse. You're obviously open to the concept of "the more money, the better," so you don't really have a maximum amount of money you're willing to be paid. Since your "minimum" is way below what they are offering, the trick is to not show the desperate eager $$ signs in your eyes. The trick is to get a good deal while making them think they got a good deal. Studies show that employers usually pick a max salary they are willing to pay, and reduce it by 15-25% and make that their initial offer, so you can probably talk them up to 75k-80k if you're good at selling things, namely: yourself. If you're really really confident in yourself and your abilities or at least in your ability to sell snow to Alaskans, you can throw out 90k-95k and negotiate down to that 75k-80k. I wouldn't recommend this unless you are a pro at sales, and considering you're here asking this sort of question, I think it's safe to say you're not. I safer thing to do is start at what you believe their maximum is, and try to meet somewhere in the middle. Don't come out and immediately say "Let's meet in the middle." If you do that at the beginning, they will more than likely know that you were just calculating numbers and going through the motions. You have to be convincing. You shouldn't want to give up money any more than they want to give up more money. Just remember, their "starting" offer is already way more than what you're willing to take, so you're already getting a good deal. You just can't let them know that. Once they up their offer even one time, it's over, you won, because they've openly to your face have gone from generic offer to "this is what we are offering you". All you have to do is play it cool. Don't let the eagerness show. They moved up to around 68k-ish, you moved down to like 73k-ish, whatever. You can go another round if you want, or you can probably safely play the "Let's compromise, 70k" card. You just have to pay attention and judge how it's going. And you need bargaining chips. That's what those pieces of paper from colleges and cert companies are for. They serve no other purpose in your career other than to help you negotiate a job. Since you're self-taught, you're at a disadvantage from the getgo. I hope you have a decent portfolio to point to, or you have a silver tongue and can convince them that you're the answer to their prayers. Which...isn't really that hard of a thing to do. People will react to all kinds of stupid things like big words, winks and nudges, ego strokings, etc... the trick is figuring out what buttons to push. -
try this: preg_match('/' . preg_quote($start, '/') . '(.*?)' . preg_quote($end, '/') . '/s', $data, $matches);