Jump to content

The Little Guy

Members
  • Posts

    6,675
  • Joined

  • Last visited

Everything posted by The Little Guy

  1. Hmm... Looks like I got it: val = val.replace(/^ \* (.+?)(\n|$)/gm, "<li>$1</li>"); val = val.replace(/(<li>.+<\/li>)/igm, "<ul>$1</ul>"); Any suggestions?
  2. I have a string of text That could look like this: I am a paragraph * I am a list item * I am another list item * I am a third list item I am another paragraph What I would like to do, is convert the asterisk lines to an un-ordered list, The format would be: space asterisk space line of text What kind of regexp would be needed for something like that?
  3. I think I found something that may work: https://github.com/paulgb/simplediff/blob/master/php/simplediff.php
  4. I am writing a site where you can edit answers users provide. I am wondering, how can I use php to do a diff on two strings, and then also merge two strings into one, similar to the way git works. Does anyone know how this can be done or is their a library available to do both of these things?
  5. The question doesn't contain an "IF" it's contains a "How". Sorry if I am being confusing. Here is the full query I am asking about, this is how I am assuming it is done, correct me if I am wrong: <?php $sql = $pdo->prepare("select sql_calc_found_rows question, question_id, count(a.answer_id) total, match(question) against (:q in boolean mode) as score from questions q left join answers a using(question_id) where match(question) against (:q in boolean mode) and q.deleted < 4 and (a.deleted < 4 or a.deleted is null) group by q.question_id order by score desc limit $limit, $max"); $sql->bindParam(":q", $_GET["q"], PDO::PARAM_STR); $sql->execute(); $numrows = $pdo->query("select found_rows()")->fetchColumn();
  6. But what if I have a limit in the query, and I want to know how many would have been returned, don't I still need sql_calc_found_rows
  7. Their isn't a num_rows, that is for php's mysql and mysqli...
  8. I am learning PDO with MySQL, and was wondering how can I do 2 queries? <?php $sql = $pdo->prepare("select sql_calc_found_rows ..."); $pdo->execute(); With that how can I run select found_rows()? Is it safe to do this? <?php $sql = $pdo->prepare("select sql_calc_found_rows ..."); $pdo->execute(); $numrows = $pdo->query("select found_rows()")->fetchColumn();
  9. I am making a template library I am extracting data from a template, like this one for example: <!DOCTYPE html> <html> <head> <title>If/Else</title> <body> $if($get.id == 0): <span style="color: green">GET is 0</span> $elseif($get.id == 1): <span style="color: yellow">GET is 1</span> $elseif($get.id == 2): <span style="color: yellow">GET is 2</span> $else: <span style="color: red">GET is not Set!</span> $endif; </body> </html> What I have now, is I extract all the required data that I need between ( and ) for each if, elseif using some regexp. in my php have have the following after the data is extracted: <?php // Extrat the data and make these variables: $ifStmt = "$get.id == 0"; $ifElseStmts = array( [0] => "$get.id == 1", [1] => "$get.id == 2" ); Now the question that I have is that need to evaluate each one until I find one that gives true as a result. I was thinking of doing eval, but that isn't really secure, so any suggestions on what I should do to evaluate the if statements?
  10. I think I got it! Here is the code I came up with (suggestions?): preg_match("/^[\p{Latin}\p{Nd}\p{Common}]*$/u", $str);
  11. I am using the code (at the bottom) to test some strings for non-US characters, the following code is returning: int(0) int(0) int(0) The result I am looking for is the first and thrid dump should be 0 and the second dump should be 1 like so: int(0) int(1) int(0) Here is my test code: <?php $str[] = '漢語'; $str[] = 'abc123'; $str[] = '漢語abc123'; foreach($str as $s){ var_dump(preg_match("/^\p{Common}*$/u", $s, $matches)); } What can I do to get the results of the second block?
  12. iTunes has always been shitty. Spotify is so much better
  13. Got the formula! f(x) = x*2 - 100
  14. I have been developing an android app, and I am stuck on some math (One thing I am not too good with). So, I have a slide bar that you can drag left to right. By Default all the way left is 0 and all the way right is 100. I am trying to find a formula that will make all the way left will simulate -100 and all the way right will simulate +100 and 0 would be dead center. For those not familiar with android programming, the event passes a position value to the event listener, which is a number between 0 and 100. I would like to take that number and convert it from -100 to +100. Thanks for the help!
  15. Is it possible to exit an array_walk_recursive? I tried doing return true/false but it still goes through all the options, is there a way for it to break out? What I wanted to do was to test certain values within a session, but the values are in different locations of the session. We have an unknown amount of steps to test, and an unknown amount of options in each step, and we only want to test the "required" fields. If it isn't possible, I guess I will just have to do nested foreach loops. Example Session Layout: $_SESSION["ad"]["fields"]["step1"]["required"][$field_name] = "some value"; $_SESSION["ad"]["fields"]["step1"]["required"][$field_name] = "some value"; $_SESSION["ad"]["fields"]["step2"]["required"][$field_name] = "some value"; $_SESSION["ad"]["fields"]["step2"]["optional"][$field_name] = "some value"; $_SESSION["ad"]["fields"]["step3"]["required"][$field_name] = "some value"; $_SESSION["ad"]["fields"]["step3"]["required"][$field_name] = "some value"; $_SESSION["ad"]["fields"]["step3"]["optional"][$field_name] = "some value";
  16. I am fairly new to Java. So, my question is: public myClass{ public Object avgRGB(int img){ // Some unrelated code to the problem Object avg = new Object(){ public double red = 0.0; public double green = 0.0; public double blue = 0.0; public double bw = 0.0; }; avg.bw = ((red / count) + (green / count) + (blue / count)) / 3; } } With, "avg.bw = ..." my Netbeans editor is giving me an error: "can not find variable bw" Why not?
  17. When building a class (or any php only file), do you add a closing "?>" or leave it out? Personally I leave it out to avoid "header" errors, but what do you do and what are your thoughts about keeping it or leaving it out?
  18. How to run for mayor of SimCity:
  19. I wonder how many people can be in a region....
  20. Grandma's Boy: http://www.imdb.com/title/tt0456554/
  21. Today is the broadcast of Live Maxis gameplay! Watch now: http://www.origin.com/maxis-live
  22. Sorry, but I think you're misunderstanding. @font-face{ font-family: henry; src: url('/media/fonts/HenryMorganHand.ttf'); /* IE9+ */ } h1{ font-family: henry, verdana, arial, serif, times; } The font is downloaded and used by supported browsers. I am just wondering why it can't render it as nicely as it can render installed fonts.
  23. I am mostly just venting in my first post, but if you think about it how can a browser render a font like verdana, arial, times, etc. fine, but if you use some custom font the browser becomes completely lost and can't render it nicely... In my opinion, you would thing that it could do it just fine since it renders the font the same way it renders a font like my previous examples.
  24. Why does the web render fonts so much worse that photoshop? Is there a way to optimize a font for the web?
×
×
  • 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.