-
Posts
571 -
Joined
-
Last visited
Everything posted by Anti-Moronic
-
DOH. Thanks. Really should learn my array functions!
-
I have this array: Array ( [jan] => 2 [feb] => 1 [mar] => 2 [apr] => 1 ) ..and I want to return: Array ('jan', 'mar') As in, find the 2 elements with the highest count and put them in an array. What is the simplest way to achieve this?
-
My friend, use jQuery instead. You will have an easier time. Even if you know little about javascript - start with jQuery. learn selectors or something. We'll need to some example html for the generated rows. Are you wanting to hide this info via AJAX or just using js like a 'quick hide' feature?
-
Good example, but the trouble with that is if the draw() number exists it will generate another draw() number without verifying if that also exists. Would be better to define the numbers and have them removed from a number map so they cannot possibly re-occur. Of course, there may also be a better way..
-
Say I have this array: array( 0 => time 1 => time 2 => to 3 => to 4 => to 5 => fly ); and 2 variables - $occMin and $occMax as number of occurrences. If: $occMin = 2; $occMax = 3; I want to produce sorted list with most occurrences at the top: array( 0 => array('to', 3), 1 => array('time', 2) ); My face just melted at the thought of even beginning to tackle this. Is this somewhat possible? would it require a monster function or am I missing some native php functions which could lend a hand?
-
Struggling with a regex match. Appreciate any help..
Anti-Moronic replied to Anti-Moronic's topic in Regex Help
Thanks for the response. Strip tags only removes the tags and so would leave the link text still there. I need to remove all links or tags of a certain type and their content. That is why I would remove the links and text but not remove the content within the div. Thanks. -
Here is the text: <div class="left">Lorem Ipsum is simply dummy text of the printing and</div> typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scramble'd it to make-shift type <a href="google.com">specimen book</a> and something [tag]else[/tag]. Essentially what I'm trying to do is extract all of the words above while abiding by these rules: 1. word can contain dash and apostrophe (scramble'd and make-shift above) 2. word cannot be within a link tag 3. word cannot be within a block tag - [tag] 4. word cannot be part of a tag name or html (class in class=", div, a, tag etc) That's about it. Any advice on where I might start with that? I'm currently experimenting with it but all I have is this: (\s?)[a-zA-Z0-9\'\-]+(\s?|\,|\.) Shameful, I know.
-
From my perspective, if it has code that I don't use then it is bloated. Yes, but bloated has a definition. It isn't opinion. Simple fact is: if you don't use a framework you're wasting time and losing money. If you build your own framework, unless it is for commercial reasons, you're learning, bu wasting time, and losing money. ON top of that, don't just walk into projects thinking you can use your own framework. Big clients understand the value in using a well known framework: pool of developers who are instantly qualified to make amendments. If you want less bloat, use a loosely coupled framework. Most modern frameworks are like this now - Zend Framework, Symfony2 as examples. Whatever you do, at least learn a framework I can have a blog built with admin capabilities, user registration, everything within 30 minutes by using a framework because I already have the module to plugin to that framework.
-
Let PHP do the work or let JavaScript do the work?
Anti-Moronic replied to unemployment's topic in Application Design
There are pros and cons of using either. PHP will work regardless of the browser, PHP will likely be faster (but that doesn't mean it will *seem* faster to the client). This is important, although PHP will be parsed faster, it will not seem that way to the client if you, for example, use AJAX. If you use PHP to change some text on a page based on a value in a cookie, you really think that will be faster than using javascript to do the same thing? Not at all. JS will win in speed just because it is directly parsed by the browser in real time, even if the actual parsing takes longer. So, if you don't mind sacrificing some independence, use Javascript. Then if need be, use PHP as well. Don't forget, using PHP will also put stress on the server. Won't matter to most but when you're dealing with enterprise applications it is extremely important you don't waste resources processing something the browser can process. -
I am developing a very complicated(i think) site SOS!!
Anti-Moronic replied to learningtocode's topic in PHP Coding Help
This is terrible. If you are developing a complex application/website, do yourself a favor and use a framework from the beginning. That will teach, almost enforce, best practice application design and coding standards. My advice: start again with a framework. Good frameworks: Zend Framework, and Symfony2 is a breeze to work with. -
Stuck on what appears to be a simple regex..
Anti-Moronic replied to Anti-Moronic's topic in Regex Help
Yep, works great Thanks so much!! -
Stuck on what appears to be a simple regex..
Anti-Moronic replied to Anti-Moronic's topic in Regex Help
Wait...I think this is working! -
Stuck on what appears to be a simple regex..
Anti-Moronic replied to Anti-Moronic's topic in Regex Help
Thanks Jay, I really appreciate your input but those are just examples. I could send over a 100 examples - the main thing I am trying to validate is point 2) above. For example, this should also match: 012-345-69 even: 0-1-2-3-4-5-6-9 or 0 1 2 3-4-5-6-9 String cannot begin or start with dash. after each number there can only be a dash, space or another number, and after each dash or space there cannot be another dash or space. Thanks again. I've validated based on specific examples, but as soon as I try to write one which matches all I get stuck. -
Stuck on what appears to be a simple regex..
Anti-Moronic replied to Anti-Moronic's topic in Regex Help
Thanks! Sadly, according to 2 your assumption would be incorrect. That is just an example of a match. A few more matches: 01-2-345 69 012 345 69 012345-69 This is the trouble I had. I am having to match based on each number and the adjacent character. Also, I cannot trim, this must run without trimming dashes. Any other ideas? -
What you should do is build in validation methods. Like: private function validConnection() { if($this->connection){ return true; } if($this->connection = mysql_connect($this->dbData['host'],$this->dbData['dbuser'],$this->dbData['dbpass'])){ if(mysql_select_db($this->dbData['dbname'],$this->connection)){ return true; } return false; } return false; } Then you use: if($this->validConnection()){ //do queries } ..which should be inside a query method. That way, you know if there are any connection problems, selecting db etc before you even attempt to run any queries. When you run your 'get()' method, you need to check for results before you start iterating over them. As a quick test, add this to your sql functions: mysql_select_db("oop") or die(mysql_error()) Same with mysql_query, and mysql_connect. Don't use this after you know the problem, have these errors stored in an array within your class, and output if you are debugging.
-
I've have been trying for too long now to understand the regex required for this. I'd appreciate any help I can get. This should match: 012-345 69 However, these should not: -012345 678 01203- 34566 1234x567 This is validation is: 1) must not begin or end with dash (-), I have trimmed to ensure does not begin or end with space 2) each number may contain a dash or space in between - however, cannot contain any combination of the two in sequence. Like dash dash, dash space, space space, space dash 3) the only other characters which can be present in the number are dash and space. Any ideas?
-
Actually..scratch that, there is some excellent documentation here: http://symfony.com/doc/2.0/book/index.html
-
This is the problem. There are no tutorials as yet on SF2, and the documentation is lacking. You're going to have to grit your teeth and keep digging. It'll click eventually
-
Using frameworks for web development is like using motorized transport to travel to work. Some people insist on walking, ie no framework. Some people insist on cycling, ie their own framework, others insist on using their car, ie a popular framework with their own twist, and others just know using the bus is the easiest, most reliable, cost-efficient solution: those are the people who use popular frameworks, and while their 'riding the bus' they have plenty of time to read the paper (study documentation). ..ok..complex and somewhat drawn-out and misdirected analogy but i'm feeling playful Point is, nearly every website you visit a framework is being used. Could be js (jQuery) or php...there is at least one framework being put to good use. For micro projects frameworks are usually overkill (the php kind) but there are even exceptions there. Use a framework, and don't look back.
-
I know it is a preview release. But I have been working with symfony 1.4 since it's release. As I understand Symfony2 has been built largely from scratch. Does anybody have any advice? I have the choice right now to use ZF1 or Symfony2, whereas ZF1 looks more stable, it is also showing it's age and I can't see ZF2 on the horizon. What kind of risk would I be taking if I used Symfony2 for production? It is not a throwaway project, but I do have plenty of time to deal with a crisis should that occur. Is anybody else planning on using Symfony2 for a new project?
-
Makes a very important point. You will have trouble finding 'advanced php' books because php itself is not that advanced of a programming language. I sometimes find myself switching off from time to time when I'm programming in php because it's so damn easy when you 'know' it. The only challenge now is keeping on top of modern web technologies. Programming in general: the rabbit hole goes very deep. Hurts my head. Oh, I'd also second that pragmatic programmer. This is one of THE best programming books I've ever read. You can see other recomendations here: http://stackoverflow.com/questions/1711/what-is-the-single-most-influential-book-every-programmer-should-read Code Complete and Pragmatic Programmer! For php: Php 5 Objects Patterns and Practice by that matt guy.
-
Which PHP Editor do you think is the best? [v2]
Anti-Moronic replied to Daniel0's topic in Miscellaneous
To be honest we can't go wrong with notepad++. Ultra fast, simple and has quite a few plugins to extend basic functionality. I can't offer an unbiased opinion as I have only used a few editors - DW, notepad++ and Zend Studio 7,8. I can't stand DW and I work with ZS on my main projects but mainly due to using Zend Framework so it all integrates very nicely. That, with project specific settings and sessions etc AND the incredibly customizable template code insertions makes it a breeze to develop in. I might move onto DW again if the next trial version impresses me.