-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
Anyways, you are over-complicating it. You don't need a for loop and a modulus. You just need one or the other. Modulus is cleaner so I'd go with that. function chunk ($array, $size) { if (!is_array($array)) return false; $chunk = 0; $pos = 1; foreach ($array as $key => $val) { $newArray[$chunk][$key] = $val; if ($pos % $size == 0) $chunk++; $pos++; } // end foreach return $newArray; } // end function chunk
-
Why re-invent the wheel? But if you really want to hardcode it, why not download the source code and look at the c code for it? php is very similar to c, so you should be able to read and see what it's doing no problem.
-
[SOLVED] Include user's ip address with web form
.josh replied to jthurstenson's topic in PHP Coding Help
http://us.php.net/manual/en/reserved.variables.server.php -
To make it a link, you would wrap anchor tags around it, just like with anything else. In order to allow thumbnails to right click > save as full sized image, you can't use thumbnail file sized images. You would have to use the full sized image and make it a thumbnail size with the img width and height attributes. Example: You have a 200x300 image named somepic.jpg, but want to show a 20x30 thumbnail: <a href='targetpage.php'><img src='somepic.jpg' width='20' height='30' /></a> Yes, this does cause the full picture to be downloaded in the first place. There's a small possibility you can accomplish what you want with ajax. That is, having a thumbnail filesized image display, but when you right click > save, it makes a request to the server for the full sized image, but I'm not sure that javascript has that much control over the browser. Maybe some javascript guru can settle that.
-
urlencode seems to work just fine for me.... $string = "Mirror's Edge™"; echo urlencode($string); output:
-
viagra lightswitch == win! Where do I get one of those.
-
They are using text that OCRs failed to accurately read from newspapers and books. I somehow doubt that the people in charge of scanning those pages to digitize printed text, are using software specifically designed to filter through captcha distorted text. Recaptcha is a project that takes the text that failed to scan accurately, and uses that to build a captcha image. If that text somehow beat out the best captcha cracking OCR software, then tell me, why does recaptcha further add their own image distortion to it? I think they have a novel idea going on, but I also think it's flawed. They depend on honest users for their project. They assume that if you are able to correctly enter in one word, you'll get the other one right. So first off, you only have to get one of the words right. Even worse, you can just enter in whatever you want for the 2nd one and they'll just take your word for it and submit it as a valid translation. Get an average, you say? You see, on the one hand, it would make sense to get a "2nd opinion" to ensure accuracy. That is, cycling the same text over and over again and picking the answer given the most. Ideally, this would be an acceptable solution. But on the other hand, that makes the captcha less secure, because you are reducing the randomness involved in the text creation. It's already not very secure, since the text (since it is coming from print) is already a real word. recycling the text makes it even less random, making captcha cracking software able to further exploit the captcha system. So the bottom line is this: The idea of Recaptcha is that people out there are trying to digitize printed text, and OCR software is flawed, so people have to hand-verify words all the time. Well, people are already doing that through captcha systems, so it sounds like a great idea to mix the two. But the more they try to ensure verification accuracy, the less secure the captcha will be. It's a brilliant idea, on paper. But the reality is that in order to ensure captcha security, they have to add on their own image distortion, so at the end of the day, they are no better than some other captcha system, security-wise. In fact, as mentioned, they are less secure, because 99% of the time, you're verifying a real word, instead of random text.
-
If an employee is expected to receive a tip for a service rendered (not restricted to waiting), the employer can pay a reduced hourly wage, based on how much tips per hour the employee is on average, expected to make. But, at the end of the day, the employee is required to report how much tips (s)he made, and if $hoursWorked / ($tips + $reducedHourlyPay) != $minimumWage the employer must pay the difference to meet minimum wage. In my experience as a waiter (and from talking to a lot of other people with serving jobs), most employers have a simple little calculator on their computer to tell you what the minimum amount of tips to claim to meet minimum wage, and they "unofficially" require you to enter in at least that amount. If you don't, then they will find a real reason to fire you. I don't entirely think it's unfair for employers to do that, because overall, most servers do, in fact, make more than minimum wage. And most servers I've known are more than happy to only claim the minimum required when they made a lot more, but try to claim less than the minimum on a slow day.
-
php library to rip all html tags except a h1 and <b>
.josh replied to jjk2's topic in PHP Coding Help
he wants to remove all tags except those tags. -
I have no idea, as I have never done tech support through email before. I imagine it must be at least minimum wage, because the whole point in minimum wage is that there's nothing (legally) lower. It could be anything more than that, though. I hope you found my post helpful.
-
In this case, you can return a multi-dim array which would be the easiest, or you could array_push $times onto the end of $array (or array_unshift it to the beginning of $array, either way), and then array_pop or array_shift it back off, once it has been returned.
-
It's not a matter of necessity, but of good practice. Sure, you can code around it, but later on down the road, your code will be harder to follow and debug and expand upon, because you're just not sure what can be changed where. That's the point of staying within scope. If you pass the value of something to a function, the function creates its own local variable. What it does inside that function will not change the variable on the outside. That way, you don't have to worry about your variable being overwritten if you need that original value later on. If you want the value returned to the outside world, you can return something from a function. If you were to try and use global variables in the same situation, you would have to make a temporary copy of the variable, then mess around with it, then assign the original value back to the global variable. When you pass something through an argument, you don't have to do all that; php does that step for you. Like Vegas, you know that whatever happens in the function, stays in the function. Same thing for classes. Classes have even more layers of scope. You can have variables accessible to code outside of the class (public). You can also make them only accessible within the class that made them (private), and accessible within its own class and any class that extends that class (protected). The whole point in functions, and moreso, object oriented programming, is that you have a piece of code that is self-contained so you don't ever have to touch the insides of it, ever again. In order to adhere to that philosophy, you must contain the scope of the variables. You don't want people being able to mess around with internal variables, from the outside. Doing so makes the function unstable. The only way you can have a stable, secure function or method or class is if you know for absolute certain that no matter what, when you call it, it's going to do the same thing, every single time. Allowing code to disregard scope breaks that security. I'm sorry you read in some book that it's okay to do that, but it's not. It's not good programming practice.
-
You know, like the same thing you did with $array.
-
OR...instead of disregarding scope, you could like, pass it as an argument to the function, and then you'd be a coding superhero instead of a superzero.
-
assuming you use the post method... $totalMarked = count($_POST['mentee_list']);
-
enjoy. <?php echo <<<WEDONTWRITECODEFORYOU IF($_SESSION[groupid] = 'A' echo("here"); WEDONTWRITECODEFORYOU; ?>
-
php library to rip all html tags except a h1 and <b>
.josh replied to jjk2's topic in PHP Coding Help
you will have to make sure no broken tags exist, yes. strip_tags does not validate html, so it may produce unexpected results. -
php library to rip all html tags except a h1 and <b>
.josh replied to jjk2's topic in PHP Coding Help
strip_tags -
okay well then you can try copy("http://www.somesite.com/somepic.jpg","somepic.jpg");
-
depends on how you are retrieving the file. Through a form upload? Look into $_FILE and move_uploaded_file(). Grabbing it some site? Look into the GD library to create an image source out of it and save it.
-
PHP Error fopen Issue Webmaster Says Its Not A Problem
.josh replied to newbie_101's topic in PHP Coding Help
now to be fair, if the form is asking you to upload a pic or provide a url to a pic, and you point it to a path/to/pic that doesn't exist, it will give you that error. So it might be kind of both of you guys' fault. Yours for providing a path/to/pic that doesn't exist, and theirs for not properly handling errors so that it just dumps you a raw error. -
PHP Error fopen Issue Webmaster Says Its Not A Problem
.josh replied to newbie_101's topic in PHP Coding Help
if this is just some random xyz site you are going to, it's their problem. If it's your script on some hosting plan/server, it's your problem. -
ah that's a preg_replace only modifier. Okay but still, I don't really see why you need that in there.
-
Since your variable is created outside of a method or function, it is accessible everywhere else on your page, except for inside a method or function. If you want to use it inside a class or function, pass it as an argument to the method or function. Conversely, if you create a variable inside a method or function and want to use it outside of that method or function, assign the method/function to a variable and return the value inside the method/function; it will be assigned to that variable. If you are wanting your data to persist from one script to another, assign it to a session variable, or store it in a database, flatfile or cookie. In short, making variables global is generally bad practice, because if you make a variable without scope, it makes it harder to track what is happening to it throughout your code.