Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. You want to remove it from the array? foreach ($data as $key => $value) if (empty($value)){ unset($data[$key]); var_dump($value); } else { ... var_dump will return NULL because it's... null.
  2. By remove do you mean not display them if it's empty or what? You can use empty to determine if it's empty or not. We really need a better explanation & relevant code to help, you just posted an example from the manual.
  3. If you're not getting any answers perhaps you should try to rephrase your question. I'm not entirely sure what you're asking. Maybe you're looking for something like cURL to post data remotely?
  4. Or you can use the built in function made to do this, pathinfo. echo pathinfo('example.jpg', PATHINFO_EXTENSION);
  5. I think the better question to ask here is what are you doing right? Assuming for the minute that the concept was correct your syntax for the following is incorrect. $i < 1 && => 49 You have to do it like this: $i < 1 && $i => 49 Addressing the logical problem, in your script $i will never be less than 1 (you set it to 1 right before this!). You also shouldn't have a semicolon after while(...) (see the manual on control structures. Finally, you can't just do something like this: print odd $v; To solve your question to print out all odd numbers 0-49, you could take an approach like so: for($i = 0;$i < 50;++$i) { if($i % 2) { echo "$i is odd!<br />\n"; } } See arithmetic operators for more on the modulus operator.
  6. Btw, the reason what you did wasn't working is because once you return something from a function it doesn't continue processing, that's the end of the function. So you can't return from a single function call multiple times. Edit: Oh, and also to address the indirect question a bit: What the person in the blog post you read was talking about was programming functions without side-effects. I'd suggest reading this article for more information: http://en.wikipedia.org/wiki/Side_effect_(computer_science)
  7. Well what did you replace that with? A suitable replacement would be something like the following: ... $result = ''; while ($row = mysql_fetch_array($result)) { $result .= "<option value=\"" . $row["cat_id"] . "\">"; $result .= $row["category_name"]; $result .= "</option>"; } return $result; ... echo function_name();
  8. No it doesn't. Even if you have cookies enabled the first time you visit the page you will get a "cookies must be enabled" message.
  9. Can you post your entire code? It will help us identify your problem much more easily.
  10. You need to establish a connection to the server before you can use mysql_real_escape_string.
  11. No, that won't work either. Cookies are sent to the server upon every request. Because you set that cookie after the request was made the cookie won't populate the $_COOKIE super-global until the next request of the page.
  12. That won't work. If you read the documentation on setcookie you'll see that the return value of the function does not specify if the client accepted the cookie or not. You can see one method of doing this in PHP here.
  13. You're welcome. By the way, there's a way to mark a topic solved at the bottom left of the page.
  14. Your problem could be that you're accessing the web page without the www. and the AJAX request includes the www In that case you should either force www or no www or do something like this: xmlhttp.open("GET","http://" + location.host + "/lib/getMessage.php",true);
  15. Make a simple function to check if any of the array values contain an array, like so: function contains_array($arr) { foreach($arr as $item) { if(is_array($item)) { return true; } } return false; } Then inside the loop in the other function I provided: ... if(strtolower($key) == 'build_date' && is_array($val) && !contains_array($val)) { // ... } ...
  16. How are you supposed to know when an array should be imploded to form the value, or if it contains values that should be separate hidden inputs? You have to have some indication, there isn't a function to read minds.
  17. You need a colon there. See the manual on alternative syntax.
  18. You should use a recursive function. Try something like this: function hidden_fields_recursive($arr) { foreach($arr as $key => $val) { if(is_array($val) && strtolower($key) == 'build_date') { echo "<input type='hidden' name='$key' value='" . implode(',', $val) . "' />"; } else if(is_array($val)) { hidden_fields_recursive($val); } else { if(strtolower(substr($key, 0, 6)) == 'build_') { echo "<input type='hidden' name='$key' value='$val' />"; } } } } $arr = array( 'build_AGE' => 20, 'foo' => 15, 'BUILD_OPTIONS' => array( 'build_HOUR' => 06, 'build_MIN' => 10, 'build_DATE' => array( 'month' => 6, 'day' => 14, 'year' => 2010 ) ) ); hidden_fields_recursive($arr);
  19. print always returns 1. I think you mean this: <?php echo isset($update_array[17])? trim(htmlentities($_SESSION['aao'],"1")) : ""; ?>
  20. ~<meta name="keywords" content="([^"]+)~ $str = '<meta name="keywords" content="grab-this-content" />'; preg_match('~<meta name="keywords" content="([^"]+)~', $str, $matches); print_r($matches);
  21. Your example won't work because single-quotes don't have variable interpolation. If you use double quotes, and escape the other double quotes in your string, it will work.
  22. Use indexOf: if(input.value.indexOf(' ') != -1) { // Contains a space }
  23. The way I have it is from the longest period of time to the smallest, So 10 06 13 17 02 00 (y m d H i s) I can then test $myarr['banend'] > $ctime, Which if returns false I can let the user reactivate thier account. I'm sure there are much easier ways to do it but I'm a dumb kid and put to practise the first thing that comes into mind. I agree with Daniel. Why couldn't you do that with a normal timestamps? There's no need to convert it to your own format.
  24. Alex

    !is_int

    What's is_not()?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.