|
This is my array.code:
code:
|
# ? Sep 20, 2012 17:14 |
|
|
# ? Jun 2, 2024 18:02 |
|
stoops posted:This is my array. Yes, although why do you want it to look like that? PHP code:
|
# ? Sep 20, 2012 17:29 |
|
stoops posted:This is my array. Working specifically from what given, and assuming "0" will always end up being blank: PHP code:
|
# ? Sep 20, 2012 17:33 |
|
Golbez posted:I was surprised you can have a blank string ('') for an array key, but here we are. From the interactive prompt: code:
|
# ? Sep 20, 2012 17:52 |
|
McGlockenshire posted:From the interactive prompt: IIRC all array keys are strings. Even the default numeric keys are really the decimal string representations of the nonnegative integers.
|
# ? Sep 20, 2012 17:53 |
|
<?php $options = array( 'english' => 'english', etc... ); ?> <select name="options"> <option value="0">Choose type...</option> <?php foreach ($options as $o) { ?> <option value="<?php echo $o; ?>"><?php echo $o; ?></option> <?php } ?> </select>
|
# ? Sep 20, 2012 17:59 |
|
Golbez posted:Working specifically from what given, and assuming "0" will always end up being blank: Thanks for this. Hammerite, The reason I wanted to do it this way is because I'm getting the arra values from a database and i wanted to populate the select box with these values. The thing is, what gets submitted to the form is '0' or '1' or '2' etc, and I wanted to submit a more friendly string.
|
# ? Sep 20, 2012 18:09 |
|
Hammerite posted:IIRC all array keys are strings. Even the default numeric keys are really the decimal string representations of the nonnegative integers. Looks like it's the other way around - numeric strings are cast to integers. Can't say this makes me happy. The bit about floats being cast to ints ... hasn't bitten me in the past but that doesn't mean I don't like it. Here's the documentation: PHP.net posted:Additionally the following key casts will occur: Golbez fucked around with this message at 19:18 on Sep 20, 2012 |
# ? Sep 20, 2012 19:15 |
|
We're getting 5.3 this weekend! And MySQL 5.5! I've been trapped in a 5.1 gulag for years. What massive stuff do I need to know about from 5.2 and 5.3? The short list I've come up with in the last 30 seconds is: 1) Array dereferencing, gently caress yeah. 2) Namespaces. Know nothing about them or why they're useful. What is the point? 3) Frameworks. Oh god, frameworks. I so very much want to move our site to a framework. But, being in 5.1, my only experience is with an old version of Zend. What is the current hotness? 4) InnoDB. This is MySQL, but it also means I have to change many many many of our queries to handle transactions. We're not converting from MyISAM immediately but it's something we'll be doing. 4a) mysqli or PDO. Oh gently caress me I've been wanting this for so long, it's not that I couldn't but I always wondered if there was any point without a framework. ... There probably is, actually, and I could just shoehorn one in, but eh. This point is more e/n than anything else. 5) I will be using the poo poo out of the datetime objects. Anything else? I'm excited!
|
# ? Sep 21, 2012 16:03 |
|
Golbez posted:We're getting 5.3 this weekend! And MySQL 5.5! 1) That didn't happen until PHP5.4, so don't go using it yet. 2) I love them. Instead of having a long class named Zend_Db_Something_Or_Other_Factory, you could throw that in the Zend\Db\Something\Or\Other namespace, and your class would just be named Factory. Then to use it, you can do: use Zend\Db\Something\Or\Other\Factory; $f = new Factory; You can also alias Factory to another name to avoid conflicts: use Zend\Db\Something\Or\Other\Factory as ZendFactory; $f = new ZendFactory. 3) Symfony2 and Zend2 just released new versions of their frameworks. I'm partial to Symfony2 personally but I have no experience with Zend2. 4) Good, hopefully you'll be using PDO (or an ORM which will use PDO). 4a) Always use PDO. "But mysqli is nice!" Nope, just use PDO. 5) DateTime is a great library. I urge you to just upgrade to 5.4. That way you can get array dereferencing and you get the built in server which is awesome. No more setting up vhosts for small projects. Symfony2 has it built into their console: php app/console server:run Bam, go to http://localhost:8000/ and your Symfony2 app is running right there. So nice. Edit: Oh yeah, 5.4 also has short JavaScript style arrays which are nice (but harder to grep for): $a = ['a', 'b', 'c'];
|
# ? Sep 21, 2012 16:43 |
|
musclecoder posted:I urge you to just upgrade to 5.4. That way you can get array dereferencing and you get the built in server which is awesome. No more setting up vhosts for small projects. Symfony2 has it built into their console: Can't upgrade to 5.4. We gotta stick with what crumbs Red Hat throws us, for whatever reason.
|
# ? Sep 21, 2012 16:47 |
|
Golbez posted:Can't upgrade to 5.4. We gotta stick with what crumbs Red Hat throws us, for whatever reason. Bummer . 5.3 at least is a huge step up from (I'm guessing 5.1.6 which is what shipped with RedHat/CentOS forever). What version of 5.3? If you use any XML-RPC libraries, 5.3 earlier than 5.3.8 has a bug with them. That was the biggest (and only) thing that got me with 5.3.
|
# ? Sep 21, 2012 16:52 |
|
musclecoder posted:Bummer . 5.3 at least is a huge step up from (I'm guessing 5.1.6 which is what shipped with RedHat/CentOS forever). Yeah, 5.1.6. It annoys me. As for which 5.3.x, I don't know, but knowing Red Hat they've probably stayed on top of that.
|
# ? Sep 21, 2012 17:04 |
|
Man, reading this thread really makes me want to get my teeth back into a bit of PHP. The last time I really touched it was with the release of PHP 5 and the whole OOP thing. I create apps in .Net at work but there's something about PHP which makes it much more enjoyable to code in. Are there any must read articles I should look at to talk me through the major new features in the last few years? Or just feel free to throw some words at me and I'll look them up. Also, this has probably been asked a million times but what's generally considered the best template system these days? Last thing I used was smarty.
|
# ? Sep 21, 2012 21:04 |
|
PHP has matured, but still has years and years of lovely history you have to put up with. Most of the things that you find in PHP you find in other competent development teams: * Automated testing of all types * Builds with Phing * Continuous integration * Continuous deployment * Database migrations * Vendored code * http://www.12factor.net/ is a great site by Heroku showing what a good web app is made up of. Definitely not Smarty. I use Symfony2 which uses Twig and I find it enjoyable. One nice construct I like is the {% for %} {% else %} block: code:
|
# ? Sep 21, 2012 21:50 |
|
Php is already a template language, especially with short tags & alternative syntax, why throw another one on top of it?
|
# ? Sep 21, 2012 23:43 |
|
Golbez posted:We're getting 5.3 this weekend! And MySQL 5.5! 4a) PDO is vastly better than MySQLi. That's my own experience, anyway. 6) Late static binding. gently caress yes. Objects get more useful!
|
# ? Sep 22, 2012 00:07 |
|
Is there any advantage to array dereferencing other than saving a line of code?
|
# ? Sep 22, 2012 02:16 |
|
It saves a line of code and a temporary variable. It's not much, but it adds up. Consider it a quality of life / syntactic sugar thing.
|
# ? Sep 22, 2012 03:55 |
|
Thanks musclecoder. That link should come in handy as I've picked up a lot of bad habits in my current place.KARMA! posted:Php is already a template language, especially with short tags & alternative syntax, why throw another one on top of it? I just like to keep the back-end code and design separate from one and other. I find it a lot easier to develop like that I guess.
|
# ? Sep 22, 2012 09:09 |
|
Probably a quick dumb thing, but I forgot how to do this: How would I push an empty array into another array, with the array's key named whatever is in (string) $p['intToken'], so I can later push something else into $teams[$p['intToken']]['whatever']?
|
# ? Sep 22, 2012 09:35 |
|
Biowarfare posted:Probably a quick dumb thing, but I forgot how to do this: PHP code:
|
# ? Sep 22, 2012 20:58 |
|
I'm pretty drat new to php, and I'm trying to wrap my head around php's read_exif_data function. As a test, I want it to read the data's "Make" tag and echo text depending on if the make is a certain one. So far I have this: php:<?php $image = "IMG_20120922_125625.jpg"; $exif = exif_read_data($image,"Make", 0, false); if ($exif == "HTC"){ echo "HTC"; } else{ echo "Not HTC"; } ?> Any advice? Experto Crede fucked around with this message at 12:01 on Sep 23, 2012 |
# ? Sep 23, 2012 11:59 |
|
Experto Crede posted:I'm pretty drat new to php, and I'm trying to wrap my head around php's read_exif_data function. As a test, I want it to read the data's "Make" tag and echo text depending on if the make is a certain one. Is it something as simple as changing $exif == "HTC" to $exif === "HTC"? I can't see anything else that might be wrong with it but I've never used the exif functions before.
|
# ? Sep 23, 2012 12:56 |
|
Try printing out the contents of $exif.
|
# ? Sep 23, 2012 13:16 |
|
Jabor posted:Try printing out the contents of $exif. This. exif_read_data returns an array, or false if it can't find anything. If you print_r($exif) you'll see how you need to reference the returned array to get what you want. (It'll probably be something like $exif['Make'])
|
# ? Sep 24, 2012 10:22 |
|
bobthecheese posted:4a) PDO is vastly better than MySQLi. That's my own experience, anyway. Yeah, PDO makes sense, especially since we are open to switching away from MySQL in the future. As for late static binding, it seems useful, but my objects are so pedestrian and simple as to only barely inherit, let alone do anything complex enough for that. Oh, and speaking of sighs, guess what upgrade was put off a week? Cmon, guess.
|
# ? Sep 24, 2012 14:38 |
|
I've been trying to get my head around Zend studio and the framework in general the last couple of days. Apart from the manual, are their any decent articles to get me started? I'm still trying to get my head around the models/controllers/views stuff so need a beginners guide really.
|
# ? Sep 24, 2012 18:14 |
|
If you're new to MVC, Zend Framework is the worst possible choice. Especially version 1. Not that there's anything wrong with it, really. The problem is that ZF is a horribly complex beast that takes hints from Java's way of doing things. It's a bad place for beginners to start. You don't need a framework to follow the principals of MVC.
|
# ? Sep 24, 2012 18:54 |
|
Thanks man, it's certainly not as easy as I was expecting. However, I've been casually looking at jobs and a lot of them require knowledge of Zend. Not all, but a lot so I thought it would give me an advantage. Edit: I guess I'll look at MVC in general then and maybe move onto Zend in the future. Thanks for the advice.
|
# ? Sep 24, 2012 19:01 |
|
You also want to stop using the word Zend without a qualifier. Zend is a company. They produce an IDE (Zend Studio), an integrated server product (Zend Server), and sponsor but do not control the development of an open source library (Zend Framework). None of the three require the others, and knowing one does not teach you anything about the others. When talking about the framework, just "ZF" is enough to give context to most people that know it.
|
# ? Sep 24, 2012 19:09 |
|
bobthecheese posted:4a) PDO is vastly better than MySQLi. That's my own experience, anyway. I currently rent a small VPS with Linode where I run a LAMP instance which I purely use to muck around with PHP. I was previously using mysqli however from your post I decided to look into PDO and god drat it beats the crap out of mysqli. I spent some time yesterday redoing code that I'd done to use PDO instead of mysqli and it is so much easier to work with (Prepared statements rock).
|
# ? Sep 25, 2012 06:03 |
|
McGlockenshire posted:You also want to stop using the word Zend without a qualifier. Got you. Anyway, I played around with CodeIgniter last night and my god is it so much easier to pick up.
|
# ? Sep 25, 2012 17:38 |
|
SimonNotGarfunkel posted:Got you. we're using FuelPHP which has its warts, but it meant to be a 'cleaner' version of CI or something. Anyway, I've poked around for fun at Laravel and it seems really very promising.
|
# ? Sep 25, 2012 21:11 |
|
SimonNotGarfunkel posted:Got you. Personally, I would avoid CI for the fact that they don't use parameterized statements in their database drivers, and instead rely on custom built sanitizing functions. Makes me wonder what other warts are lurking in it.
|
# ? Sep 25, 2012 21:37 |
|
SimonNotGarfunkel posted:Got you. You might want to start with some of the Sinatra-esque frameworks like Silex to get a feel for MVC and then move on to one of the modern (PHP5.3+) ones.
|
# ? Sep 25, 2012 22:16 |
|
Deus Rex posted:we're using FuelPHP which has its warts, but it meant to be a 'cleaner' version of CI or something. Anyway, I've poked around for fun at Laravel and it seems really very promising. Thanks for this - I hadn't heard of Laravel and it looks quite interesting. Edit: So I've been looking into Laravel, playing around with it a bit, and I'm struggling to get the hang of the Eloquent ORM. In my schema I have a USERS table and a TEAMS table, each user record has a TEAM_ID (which may be null) representing the football team they support. I must be misunderstanding something, because I would call this a one to many (one team can be linked to any number of users, but each user will be linked to just one team). According to the docs I would reflect a one-to-many relationship in the code by saying: PHP code:
I'm clearly misunderstanding something fairly fundamental, someone please help! putin is a cunt fucked around with this message at 16:45 on Sep 26, 2012 |
# ? Sep 26, 2012 03:41 |
|
Yeah there are a lot of frameworks out there. Which one has built in models to manage users? I'd like something that already has the sign up/login/recover password thing already made and I can just extend from. I've been using code igniter because I have experience with it from a school project, but it doesn't come with user stuff already.
|
# ? Sep 26, 2012 19:19 |
|
PlesantDilemma posted:Yeah there are a lot of frameworks out there. Which one has built in models to manage users? I'd like something that already has the sign up/login/recover password thing already made and I can just extend from. I've been using code igniter because I have experience with it from a school project, but it doesn't come with user stuff already. Laravel comes with the Auth stuff built-in, it seems like it's going to be the next big thing in my opinion as it's incredibly well made and actually makes good use of the improved OO in PHP 5.3 Edit: forgot to mention, also has great documentation.
|
# ? Sep 27, 2012 06:52 |
|
|
# ? Jun 2, 2024 18:02 |
|
How recommended/good is it to shoehorn an existing site (and more importantly, an existing database schema) into a framework?
|
# ? Sep 27, 2012 17:31 |