|
SmirkingJack posted:Here's a time saving tip that can obviously be applied anywhere, but I first started using it with PHP's website. If you use Firefox then navigate over to php.net, right click on the search box and add a keyword of 'php' to the search. Now whenever you need to look up a function hit Ctrl+L (or otherwise get the focus on the address bar), type 'php <<function name>>' and there you are. It also works great if you don't remember the exact name but can come close, which is how I found imagecreatefromjpeg() from createfromjpeg(). Another way to do it in Firefox is to go to Bookmarks > Organize bookmarks. Click 'New Bookmark', set the name you want, and paste the URL of a search query in there. replace the query words by '%s'. So 'http://ca3.php.net/manual-lookup.php?pattern=myfunction' --> 'http://ca3.php.net/manual-lookup.php?pattern=%s'. Then add the keyword you want to type in. The advantage is minimal, but in search engines like google you can specify the language (hl=en,fr, etc) or some other parameters that way. Opera works in a similar manner. Go to Tools > Preferences (ctrl+F12), press the 'search' tab. You can edit those that are there or enter new ones the same way firefox does (%s). Sorry for the derail.
|
# ¿ Mar 26, 2008 03:24 |
|
|
# ¿ Apr 29, 2024 17:49 |
|
fletcher posted:Thanks for all the replies guys, very helpful and appreciated.
|
# ¿ Mar 28, 2008 01:16 |
|
DaTroof posted:I disagree. One of the benefits of using classes is the ability to use simple, descriptive member names that won't collide with the same name in other contexts. If $obj->delete() is an appropriate name for what the function does, I'd use it. The fact that it's obviously an object member instead of a global function should eliminate any confusion. I just hate it when the syntax highlight goes crazy on it and highlights it as a built-in function, which then confuses me. I can tend to be distracted, so I make what's necessary to reduce my mistakes and make it easier to read for me
|
# ¿ Mar 28, 2008 15:16 |
|
duz posted:And braces allows you to do crazy things like: They were also my only way out of some heredoc trouble with arrays: php:<? $array['john'] = "John Laurence"; //or whatever I'm just looking for a poo poo example $value[1] = 'john'; echo <<<EOF this is $array[$value[1]] and you will love him. EOF; ?> code:
|
# ¿ Apr 5, 2008 16:48 |
|
Not really sure this belongs here or the python thread, but whatever. I'm learning python on the sides and I'm noticing some stuff. Basically, python will use a bunch of elifs instead of switches/cases (as far as the tutorial told me, and I hope it's right). This means there's no nead for 'break;', but it acts the same. However, I noticed that PHP doesn't require the break; to be syntactically right. So I could do: php:<? $x = 1; switch($x){ case 1: echo "woo"; case 2: echo "haa"; break; } //this echoes 'woohaa' ?> (I also found http://simonwillison.net/2004/May/7/switch/, but it doesn't say much about the possibility to move from statement to statement like I did in PHP) edit: fixed linking MononcQc fucked around with this message at 16:35 on Apr 21, 2008 |
# ¿ Apr 21, 2008 16:25 |
|
noonches posted:I'm pretty sure PHP is working "correctly", as it were, and python is wrong. You can exclude the break in just about any language and it acts the same as your PHP example, as far as I remember. Alright, good to know, and also surprising it's not everything > PHP on this issue, like it seems to be about code-related things according to posts I read here.
|
# ¿ Apr 21, 2008 16:33 |
|
drcru posted:Gotcha. Use SHA-1. Otherwise, salting it is pretty much the right thing to do.
|
# ¿ Aug 21, 2008 13:06 |
|
Bonus posted:My PHP is really rusty and I ran into this problem when building a site for something I'm making. I have an associative array with strings as the keys and they point to arrays: php:<? #based on the array you described function getPrevNext($dict, $current_key) { $keys = array_keys($dict); $num_key = array_search($current_key, $keys); return array('prev'=>$keys[$num_key-1], 'next'=>$keys[$num_key+1]); } print_r(getPrevNext($contents,'types-and-typeclasses')); ?> code:
edit: fixed poo poo. didn't test properly and if there was no key corresponding, would return the firt one as next. This one will throw an exception if the key doesn't exist: php:<? function getPrevNext($dict, $current_key) { try { $keys = array_keys($dict); $num_key = array_search($current_key, $keys); if($num_key===False) throw new Exception ("key '{$current_key}' not in array"); return array('prev'=>$keys[$num_key-1], 'next'=>$keys[$num_key+1]); } catch(Exception $e) { echo $e; } } ?> MononcQc fucked around with this message at 16:07 on Aug 30, 2008 |
# ¿ Aug 30, 2008 15:40 |
|
windwaker posted:Ah, good idea, I hadn't thought about that (though I don't know if said red X will appear if the "image" is display:none'd).
|
# ¿ Sep 9, 2008 14:11 |
|
Safety Shaun posted:I have a huge table of articles I've posted on one of my personal sites and each entry has a tags field as such Suggestion: you should have a table possibly just for tags, then an intermediary table matching art with tags: art: art_id, art_name, art_cont tags: tag_id, tag_name art_tags: at_id, art_id, tag_id That way, you do not need to do any processing when retrieving tags (just implode them when parsing the form where they are added: parse once, not every time you select). Count, group by, order by. And you have your list. This is a much more flexible way to structure data and operate on it. This also lets you extend tags (add a description, an image, etc.) without loving up the art table. Ask yourself "Can I have art without tags?" If you say yes, then tags should probably be in another table. MononcQc fucked around with this message at 23:50 on Oct 2, 2008 |
# ¿ Oct 2, 2008 23:48 |
|
Zorilla posted:Also, there's no reason to die() the script after setting the HTTP header. PHP knows to stop it right there on its own. No it doesn't. It will keep processing and just send the header when it's done. Try this: php:<?php header('location: http://google.com'); fopen('file.txt','w'); // if you need file.txt, it will be overwritten ?> To make it better: php:<?php header('location: http://google.com'); exit; fopen('file.txt','w'); // The script died before this. ?>
|
# ¿ Nov 9, 2008 07:56 |
|
hexadecimal posted:Let's say I have a list of variables I would like to pass to my php script, such as http://someurl?a=2&b=3. What if I want to pass a string "a=2&b=3" as a single variable? like http://someurl?args="a=2&b=3". How can I do this? I tried quotes already and they don't work. Is there some particular escape character I can use or something? see http://ca3.php.net/manual/en/function.urlencode.php
|
# ¿ Jan 5, 2009 17:59 |
|
Hammerite posted:What I meant is, is it any faster at all at reading and interpreting the file? But I take it from your answer that no, it is not any faster. Thanks! The biggest speed upgrades you can have when including a file many times is to not include it many times. Usually, you'll use statements like require_once("file.php");, which are pretty slow compared to imports in many other languages. A way to bypass this is to use a defined constant once a file is loaded and check it before including it again. This makes ugly code though, and in most cases is not worth it at all. I do not recommend it. I may not have everyone's approval on this, but optimizing the server-side code is rarely what you need to do to speedup your website. Overall, you'll get a bigger speedup for the client making sure everything is gzipped and using a cache than optimizing trivial things like file imports. As a general rule, downloading images, css and/or javascript files is longer than the processing needed server-side. Otherwise, the only big bottlenecks which really have a noticeable effect are operating on large amounts of data (image rendering, nested loop on large datasets, bad written templating engines without caching ever, etc) and SQL queries (look at indexes and whatnot, also use caches if possible).
|
# ¿ Jan 29, 2009 15:30 |
|
Ferg posted:What about passing by reference when necessary? I'm currently working on a project that was shooting back enough data to crash FirePHP, so I was thinking if I passed things around by reference (since most of it is references to constant data anyways) it might help improve performance. What kind of data do you have? why does it need to be moved around? It may be that the design of the solution is not right, rather than the moving data necessary.
|
# ¿ Jan 29, 2009 16:20 |
|
I'm working on a PHP RESTful app taking zip files, unpacking them, storing them somewhere. I have a problem where php://input is always NULL. I'm using a short script that's parsing multipart-form/data content when in a 'PUT' query and it works fine everywhere except when I'm including it within another particular script, where suddenly everything fails. I still get the normal $_SERVER['CONTENT_LENGTH'] and whatnot, php://input never returns anything there. The results are also the same when using a normal upload (not multipart). I'm testing everything with these queries: code:
EDIT: forgot a very important detail: the script which includes the file happens to already read php://input. Is it supposed to be possible to be accessed only once? MononcQc fucked around with this message at 20:36 on Feb 16, 2009 |
# ¿ Feb 16, 2009 20:31 |
|
cannibustacap posted:By the way, what do you guys think of the $_SESSION variable? Does that work when a user has cookies disabled? Are there certain instances when you do not want to use $_SESSION? $_SESSION still uses cookies unless you explicitely have it put the SID in the url. What PHP does is kind of abstract away the need to manage the SID, Time to live and where to put the data (and more) and instead stores it all for you in static files. That static file is associated with the session ID which has been stored in the cookie or the url. They're nice if you don't know how cookies and session management work, but if you have the time to do it, you'd be better off learning how to do it by hand and managing it all in a database. You gain more control on what you do and can use the data outside of PHP if it's what you want (ie.: compile stats, distribute sessions over many servers, etc).
|
# ¿ Mar 11, 2009 00:10 |
|
milieu posted:Sweet! That works perfectly, thanks! I have no idea what the line you commented is for, I copied it from somewhere else. It works though so whatever! The original dev most likely tried to see if the text was longer than en empty string (0 character). This is not a really nice way to do it. There are many more ways to test this nicely: php:<? if ($node->field_images[$i]['view'] !== '') // cleaner and stricter if (!empty($node->field_images[$i]['view'])) // shows what you mean better than > '' if ($node->field_images[$i]['view']) // overall cleanest IMO ?> I suggest you go to php.net and read the documentation there. It's concise, won't show too much to stop you from 'getting things done', and while PHP's certainly not the best you could do to learn, it'll at least be better than copy/pasting stuff at random hoping it works. EDIT: also note that 'print' is rather rarely used. read http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40 for the difference with 'echo' MononcQc fucked around with this message at 20:16 on Apr 21, 2009 |
# ¿ Apr 21, 2009 20:12 |
|
|
# ¿ Apr 29, 2024 17:49 |
|
Begby posted:This is interesting How much of a moron do you have to be not to be able to use PHP with MySQL on windows? Install any WAMP stack and you're good to go. The guy is on windows and there are plenty of stacks available; I can't even comprehend how he can't get it to load dlls when it should be done without touching the config.
|
# ¿ May 13, 2009 15:17 |