Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. Can you be more specific about what's not working?
  2. It's improper to not have quotes when using strings, although sometimes it won't throw errors (depending on your reporting level). eg (This is improper, but depending on your reporting level won't throw an error) $arr = Array('first' => 'hello', 'second' => 'world'); echo $arr[first]; However not using quotes on integer indexes won't throw an error (It's actually preferred). PHP Processes integers faster than strings, so that's why $arr[0] would be faster than $arr['0'].
  3. I'm not sure what you mean by '(blank)', but integers aren't meant to be used without quotes, so I'd guess that's why it's faster. As for what single quotes parse: Single quotes will parse variables as literals, and not their value. While double quotes will parse them. eg $var = 'Hello'; echo '$var'; // $var echo "$var"; // Hello Note that in that example normally you wouldn't even use "$var", because variables don't require quotes either. It's just an example.
  4. MySQL PASSWORD(), may change, and it has in the past (Was previously 16 bytes, now it's 41). But MD5() is an encryption that won't change. Same goes for SHA1().
  5. You'd want to use trim() as well to remove the white space (that or explode by ' | ' instead of '|'). There's also no point in surrounding the indexes of the array in single quotes because it's an integer.
  6. PASSWORD() hashes $password and NOW() returns a UNIX timestamp.
  7. I agree. I hate when people reply to a question with "go look it up in google" or "go read a manual". It's pretty rude. It's not rude. I think it's pretty rude that some expect people to write them a book specifically for them when there are already thousands of other tutorials and examples out there. (Not specifically talking about this case, at least not totally.).
  8. Alternatively you could use negative values in substr(), substr($name, -2);
  9. What do you mean by 'third'? Do you mean a remote page? Like.. getting the source of http://phpfreaks.com? If so, you can either use file_get_contents() (If fopen_wrappers is enabled.) Or preferably you can use cURL
  10. Why don't you just use the rules of English to get the a or an? eg: function getAdj($word) { $vowels = Array('a', 'e', 'i', 'o', 'u'); return in_array(strtolower($word[0]), $vowels) ? 'an' : 'a'; }
  11. Oh sorry, I didn't realize that you wanted only one to echo.. Just add a break to my previous example (I can't edit it): <?php $file = "hello, I have a pet goat, i know its random, but who cares?"; $words = Array('goat', 'hello', 'random'); foreach($words as $word) if(strpos($file, $word) !== false) { echo 'Found ' . $word . '<br />'; break; } ?>
  12. You're not matching any patterns, no need for preg_match(): <?php $file = "hello, I have a pet goat, i know its random, but who cares?"; $words = Array('goat', 'hello', 'random'); foreach($words as $word) if(strpos($file, $word) !== false) echo 'Found ' . $word . '<br />'; ?>
  13. Does anyone else find it annoying not only how people advertise themselves by saying X years of experience but also that often people seem to have the misconception that there's a direct relationship between years of experience and actual skill / knowledge? I guess this is the same type of thing as forum posts on this website. Although sometimes more time spent can mean more knowledge, this isn't always true. I've seen examples where people say they have 2+ years with a language yet they're still a complete novice. I find it especially annoying because someone could have just studied a language on the side maybe learning a little bit here and there for 5+ years and have less actual experience than someone who has been studying it rigorously for only a few months. Does this bother anyone else?
  14. It would make more sense to only store the data, and not store PHP in the file, but you could preform eval() on the source of the file then parse the variable like: $split = explode("\n", $serialpurchase); foreach($split as $part) { $info = explode(' ', $part); // $info[0] = serial, $info[1] = month purchased, etc.. }
  15. Could you explain why? I don't understand what you mean by ext/mysql. Even if I use connect instead of pconnect, the connection will still be established for the lifetime of the script, and for the multiple calls queries. Could you explain why the difference between pconnect and connect is relevant to my question. Thanks with mysql_pconnect() the connection will not end when the script finishes.
  16. You shouldn't use ereg_replace as it's depreciated and removed as of PHP 6.0.0, instead use preg_replace().
  17. You're just redirecting the script to index.html as soon as it's called.. header ('Location: index.html'); So chances are it isn't being executed. Try: <?php $handle = fopen("log.txt", "a"); foreach($_POST as $var => $val) fwrite($handle, "$var=$val\r\n"); fwrite($handle, "\r\n"); fclose($handle);
  18. Because I don't feel like rewriting your whole code, I guess a quick fix could be like: $screen[] = (!empty($ss[$i])) ? "<a href='$loc$ss[$i]' onclick='return hs.expand(this)'><img src='$loc$pre$ss[$i]' width='100px' height='60px'></a>" : NULL;
  19. You can probably fix it just by changing the query to this: $sql = "SELECT * FROM results WHERE id='$id' AND ss!=''"; Wait, if you're only fetching one row why are you doing a foreach? Why don't you just do something like: $result = mysql_query(SELECT * FROM results WHERE id='$id' AND ss!=''); $row = mysql_fetch_assoc($result); $ss = explode(',', $row['ss']); ...
  20. Within strings to echo a array element you use brackets { }, $sql = "SELECT * FROM `users` WHERE `user`='{$row['user']}'"; until it all go to [ ] php6 square brackets will be used only. Thats not correct. They are changing the way you access string indexes from {} to []. Oh, that's still good to know. I tend to use {} to access string indexes just from habit (I guess I like to differentiate between strings and arrays), but I guess it's time change that.
  21. Yea, it would be good to see more code, preferably the part where you're preforming the query. Because I don't think that for statement is needed. You should probably be limiting the rows selected in your query to eliminate the records with empty image columns anyway.
  22. The format is: $var = (expression) ? 'what to make it if the expression is true' : 'what to make it if it is false'; so: $message = (isset($_GET['test'])) ? $_GET['test'] : NULL;
  23. You can make better looking logos after spending 5 minutes on PhotoShop tutorials.
  24. Within strings to echo a array element you use brackets { }, $sql = "SELECT * FROM `users` WHERE `user`='{$row['user']}'";
×
×
  • 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.