|
Wrote yourself a fancy image uploading script and want us to point out the problems? Can't figure out how to get rid of the mysterious slashes in the data from your form? Don't know why the slashes should probably be there? Need help writing OOP in PHP5? This thread will be for all that and any other PHP related issue. It does not have to be web related to be asked in here. The official site has extremely useful documentation. itskage has written up a handy guide to getting a useful dev environment setup on windows. If you're a *nix user, you should know which steps to skip. itskage posted:This has become less of a "copy the guide from these mark down files" and more of a "Retype the jist of stuff into a forums post". Sorry but there's more company specific stuff in them than I remembered, and it was quite long and I was fighting with the lack of md formatting, so I cut it down a lot, and now it is like a text dump, but hopefully it's useful to someone. duz fucked around with this message at 15:09 on Jan 18, 2021 |
# ? Mar 19, 2008 20:36 |
|
|
# ? May 15, 2024 03:19 |
|
Excellent call on the thread. PHP Frameworks: what lots of us use is: CodeIgniter A PHP5 only alternative: Kohana Link to the CodeIgniter Thread
|
# ? Mar 19, 2008 20:51 |
|
Added to the stickied list
|
# ? Mar 19, 2008 20:57 |
|
Might want to mention these two frameworks: Zend Framework symphony Couple of php ORM's Propel (1.3 is soon to be released which is a lot better than 1.2) php doctrine
|
# ? Mar 19, 2008 22:00 |
|
We should probably put the major CMSs in here as well.
|
# ? Mar 19, 2008 22:48 |
YES! A php megathread. I was tempted to ask why there wasn't one the other day. Can you combine a function call that returns an array with the array index you want like: $something = $this->arrayReturningMethod()[0]; I tried it and it didn't work. Am I doing it wrong or can you not do this in PHP? Are there languages where this does work?
|
|
# ? Mar 19, 2008 23:07 |
|
fletcher posted:Can you combine a function call that returns an array with the array index you want like: Naw, can't do that in PHP. Javascript can do what you want, don't know off hand what else could.
|
# ? Mar 19, 2008 23:25 |
|
You also can't do php:<? $bla = new Something()->method(); ?>
|
# ? Mar 19, 2008 23:51 |
|
Bonus posted:You also can't do If your just after the output of the method, couldnt you just do something like $bla = Something::method() or are you after an initialised object? Ie $address = new Customer('Dr Philodimo')->address() PHP *does* have a few holes in that regard. edit: Also x = thingo()[0] is a fairly common python idiom, as is the above, opening up awesomeness like tag = xml('file.xml').parse().findtags('customers')[3].tag('name') Maybe php6 will support it? One can only hope. edit2: Add to the php orm's , ADODB 's Active Record. duck monster fucked around with this message at 00:13 on Mar 20, 2008 |
# ? Mar 20, 2008 00:08 |
|
Imminent posted:Might want to mention these two frameworks: There's also these, which I have tried...
|
# ? Mar 20, 2008 00:15 |
|
duz posted:Naw, can't do that in PHP. Javascript can do what you want, don't know off hand what else could. Perl does this. code:
code:
|
# ? Mar 20, 2008 00:18 |
|
duck monster posted:or are you after an initialised object?
|
# ? Mar 20, 2008 00:45 |
|
Bonus posted:You also can't do You also can't do php:<? empty(someFunctionThatReturnsAString())?>
|
# ? Mar 20, 2008 00:45 |
|
Standish posted:You also can't do I hate this so much, it's stupid having to use empty() sometimes and strlen(whatever()) == 0 other times. I understand why you can't chain calls together in PHP since it sucks at OOP, but it terrible that you can't do basic things like [index] on a function that returns an array.
|
# ? Mar 20, 2008 01:01 |
|
Don\\'t should be Don\\\'t .
|
# ? Mar 20, 2008 01:43 |
|
fletcher posted:$something = $this->arrayReturningMethod()[0]; Python can do this as well.
|
# ? Mar 20, 2008 03:43 |
|
So I just upgraded my hosting environment. Went from PHP4 to PHP5 and getting this error 'Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource' for this piece of code: $rs = mysql_query($query); if (mysql_num_rows($rs)>0) { if($rsdata = mysql_fetch_object($rs)) { if($rsdata->catalog_number == "") $catalogid = "---"; else $catalogid = "$rsdata->catalog_number"; $catarr = explode(",",$rsdata->category); $imgarr = explode(",",$rsdata->picture);
|
# ? Mar 20, 2008 05:02 |
gi- posted:So I just upgraded my hosting environment. Went from PHP4 to PHP5 and getting this error 'Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource' Is the mysql_query failing? Add this after it. php:<? if (!$rs) { die('Invalid query: ' . mysql_error()); } ?>
|
|
# ? Mar 20, 2008 05:14 |
|
I've been writing PHP for my job for over a year now, and we don't use a framework. I'm going to recommend two tools that make using PHP less messy. The first is Smarty, a templating language for PHP. It's overkill for small projects, but if you're working on something bigger than one page, it can really help you avoid poo poo like "echo '<html><head>...'". If you've ever hated mixing a ton of PHP code in with gigantic blocks of HTML, you'll probably want to try Smarty. The second tool is MDB2. It's a database abstraction layer, and it has a ton of drivers, including PostgreSQL, Oracle, MSSQL, and MySQL. If you use its built in prepare and execute methods, it will escape data for you, which is very handy. Another positive feature is that it will help you avoid the multitude of mysql_real_add_slashes_im_serious_this_time_i_mean_it methods. I'm also a fan of its placeholder functions, which some databases don't support natively. Also, if you can, turn off magic quotes. It still comes turned on by default and the only thing that's magic about it is how much it pisses people off.
|
# ? Mar 20, 2008 07:14 |
|
Xenos posted:I've been writing PHP for my job for over a year now, and we don't use a framework. I'm going to recommend two tools that make using PHP less messy. Isn't PHP a good enough templating language that you shouldn't have to use another one? What's wrong with: <? //domain/controller logic //template ?> You can just declare all the variables you're going to use in your template(s) in the logic section and just present in the template. I also agree that MDB2 is super useful, I love that thing.
|
# ? Mar 20, 2008 07:18 |
|
Scarboy posted:Isn't PHP a good enough templating language that you shouldn't have to use another one? What's wrong with: It does a little more than that, it has built in validation, pagination, it auto-generates drop-down menus, radio groups, checkbox groups as well as templating. I know it seems kinda goofy to have a templating language inside of a templating language at first, but I really like it.
|
# ? Mar 20, 2008 07:31 |
|
Xenos posted:It does a little more than that, it has built in validation, pagination, it auto-generates drop-down menus, radio groups, checkbox groups as well as templating. I know it seems kinda goofy to have a templating language inside of a templating language at first, but I really like it. Ah, ok, that seems useful then. Coming from Rails, at my last job I wrote a lot of functions similar to the ones in Rails to works with form elements. Generating select boxes without having an array of options and an array of selected items is a nightmare.
|
# ? Mar 20, 2008 07:35 |
|
Here is a tip that I just had occasion to learn. If you are uploading relatively large files you not only have to make sure that in php.ini not only is upload_max_filesize set high enough but also post_max_size. I could not figure out for the life of me why there was no $_POST variable when I clicked submit until I learned of post_max_size's existence.
|
# ? Mar 20, 2008 14:46 |
|
"Unexpected T_PAAMAYIM_NEKUDOTAYIM" is my favourite PHP wtf, what do you mean not everybody speaks Hebrew?
|
# ? Mar 20, 2008 15:15 |
|
SmirkingJack posted:Here is a tip that I just had occasion to learn. If you are uploading relatively large files you not only have to make sure that in php.ini not only is upload_max_filesize set high enough but also post_max_size. I could not figure out for the life of me why there was no $_POST variable when I clicked submit until I learned of post_max_size's existence. Thanks for this. I knew about upload_max_filesize but never heard of this. It would've had me frustrated for days.
|
# ? Mar 20, 2008 17:10 |
|
functional posted:Thanks for this. I knew about upload_max_filesize but never heard of this. It would've had me frustrated for days. php_value max_execution_time X Is also another good one to throw in there. Those three are my standard .htaccess file upload fix. I was wondering if anyone could point me to a php progress bar script of some kind. I need it to be able to display sales for about 12 different entities on one page. I've been digging around quite a few sites to no avail. Im about to install Joomla to use an extension they offer, as well as Sugar CRM but both seem to be a bit of an overkill at this point for what I want.
|
# ? Mar 21, 2008 02:07 |
|
Super 3 posted:php_value max_execution_time X Super 3 posted:I was wondering if anyone could point me to a php progress bar script of some kind. I need it to be able to display sales for about 12 different entities on one page. I've been digging around quite a few sites to no avail.
|
# ? Mar 21, 2008 06:49 |
|
Standish posted:"Unexpected T_PAAMAYIM_NEKUDOTAYIM" is my favourite PHP wtf, what do you mean not everybody speaks Hebrew? That one made me shout WTF out loud
|
# ? Mar 21, 2008 15:31 |
|
minato posted:I don't put these into .htaccess because .htaccess isn't parsed if you're running a CLI script. I always either set them explicitly in my bootstrap, or in php.ini if that particular var doesn't allow it. Dont have access to the php.ini over here. More like a charting tool. Essentially it's 12 stores that all have a sales goal, that I want to show via a progress bar/graph/visual thing.
|
# ? Mar 21, 2008 21:14 |
Super 3 posted:Dont have access to the php.ini over here. http://code.google.com/apis/chart/ I used this for a project recently and absolutely loved it. Let me know if you have any questions about it.
|
|
# ? Mar 21, 2008 21:23 |
|
Super 3 posted:Dont have access to the php.ini over here. code:
|
# ? Mar 21, 2008 21:26 |
|
fletcher posted:http://code.google.com/apis/chart/ Normally I wouldn't recommend anything flash based in a php thread, but these graphs are waaay too sweet to pass over if someone is doing something in php that will need charts. http://www.maani.us/charts/index.php?menu=Gallery Super easy to configure (as easy or easier than google charts), they're free to use, but they cost 45 bucks to remove the "click on graph go to php/swf charts site". Well worth the money and the effort to get them set up if you are working on a professional project. When I got them working on one of my projects, my bosses eyes lit up.
|
# ? Mar 22, 2008 01:11 |
|
I want to parse an html file. For example, say I want to know what is contained inside an <h1> tag. I can do this with strstr and substr but it is ugly.
|
# ? Mar 22, 2008 07:16 |
|
We may want to throw in some IDE's too, I dunno. PDT - http://www.eclipse.org/pdt/ - This is what I use Aptana - http://www.aptana.com/php - I haven't used this but it looks slick. Zend Studio - http://www.zend.com/en/products/studio/ - They have an eclipse plugin now too I think Edit: ohh yeah and about the DIVs and the widths... screw static graphics use GD and draw them http://us3.php.net/gd Roloc fucked around with this message at 08:59 on Mar 22, 2008 |
# ? Mar 22, 2008 08:57 |
|
Lumpy posted:
Since we're on the topic, I really wish there was a method built into HTML/CSS that sets the widths and things automatically based on a "scale" value. For instance: code:
nbv4 fucked around with this message at 09:14 on Mar 22, 2008 |
# ? Mar 22, 2008 09:08 |
|
nbv4 posted:
Or you could add ' MAX(myValue) as theBiggest ' to your query and have it available in each row already....
|
# ? Mar 22, 2008 15:51 |
|
Kaluza-Klein posted:I want to parse an html file. For example, say I want to know what is contained inside an <h1> tag. I can do this with strstr and substr but it is ugly. If you are using PHP5, and your HTML is valid XML (which it might (probably?) not be) you can do it easily like so: php:<? $xml = simplexml_load_file('myHTML.html'); echo $xml->h1; ?> Otherwise check out the DOM and XML methods in the manual, they are pretty self explanatory.
|
# ? Mar 22, 2008 15:58 |
|
Kaluza-Klein posted:I want to parse an html file. For example, say I want to know what is contained inside an <h1> tag. I can do this with strstr and substr but it is ugly. You can use a combination of HTMLTidy to clean up the HTML and SimpleXML to search the document. php:<? $config = array( 'indent' => true, 'output-xhtml' => true, 'wrap' => 200); $tidy = new tidy; $url = 'http://www.example.com/index.html'; $tidy->parseFile($url, $config); $tidy->cleanRepair(); $doc = new DOMDocument(); $doc->loadHTML($tidy); $html = simplexml_import_dom($doc); $h1 = $html->xpath('//h1[@id="main"]'); ?>
|
# ? Mar 22, 2008 16:57 |
|
duz posted:You can use a combination of HTMLTidy to clean up the HTML and SimpleXML to search the document. That's useful if you are parsing an entire html document or a whole bunch of different tags, but if it was a one-time thing I'd probably just use php:<? preg_match("/<h1>(.*?)<\/h1>/s",$string,$h1); $contents = $h1[1];?>
|
# ? Mar 22, 2008 18:49 |
|
|
# ? May 15, 2024 03:19 |
|
Are there any benefits to using MDB2, assuming I'm already using mysqli prepared statements, won't be switching away from mySQL, and I'm not already using PEAR?
|
# ? Mar 22, 2008 19:07 |