Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. That image does have background image though.. Anyway, you mean you just want a transparent background right? imagecolortransparent()
  2. I'm not really sure what you're asking, can you try to explain your question better please?
  3. Explain your directory structure better then.. I really don't know what you meant. Using -> To explain directory structure doesn't really make sense, and does _INCLUDE signify an include, or a directory name?
  4. You put num[] so that it can be an array.. You were also creating an array with one element which was an array, which is why you were getting 0. Here: <form method='post' action=''> Enter Student's Name: <br/> <input type="text" name="num1" value = " " /> <br/> <br/> Enter Seven Tests Scores Here: <br/><input type="text" name="num[]" value = "<?=$_POST['num'][0]?>" /> <br/><input type="text" name="num[]" value = "<?=$_POST['num'][1]?>" /> <br/><input type="text" name="num[]" value = "<?=$_POST['num'][2]?>" /> <br/><input type="text" name="num[]" value = "<?=$_POST['num'][3]?>" /> <br/><input type="text" name="num[]" value = "<?=$_POST['num'][4]?>" /> <br/><input type="text" name="num[]" value = "<?=$_POST['num'][5]?>" /> <br/><input type="text" name="num[]" value = "<?=$_POST['num'][6]?>" /> <br/><input type='Submit' name='Submit' value="Submit" /> </form> <? $arr = $_POST['num']; function getAverage($arr) { asort($arr); array_shift($arr); array_shift($arr); return array_sum($arr) / count($arr); } if(isset($_POST['Submit'])) { echo array_sum($arr) / count($arr); } ?>
  5. First 1) You could use PHP sessions to store the time of the first refresh, then run a conditional to see if it has been 2 hours yet. For 2) You could do something similar, just no sessions required, just check the time of day. // 1) session_start(); if(!isset($_SESSION['first'])) $_SESSION['first'] = time(); if($_SESSION['first'] + 60*60*2 < time()) // Some refresh method // 2) date_default_timezone_set('...whatever timezone you want this based on'); if(intval(date('G')) < 15) // Some refresh method You might need to use sessions on the second way depending on how you want it to work.
  6. in_array() checks the values of an array, not the keys. Instead use array_key_exists()
  7. So it's like, commondir/Images/profile_image/tecmeister/someimage.. and trying to include it from commondir/update/_INCLUDE/main.php ? If so something like this should work: <img src="../../../<?php echo $data['imagePath'];?>" width="210px" height="auto" /> ../ goes up one directory.
  8. More than likely your problem is with the paths. You're going to have to show us how your directories and structured so we can help.
  9. Is there any reason you're actually using preg_replace(), do you want to replace things in a string, or just pick parts out? Perhaps a combination of preg_match_all() and array_map() will work for you. Something like: $content = preg_match_all('~'.$site.'(\S+\.(?:jpe?g|png|gif))~i', $content, $matches); array_map('some_function', $matches[0]);
  10. Normally a switch statement can not be used with multiple conditions, although it can be 'hijacked' to work like this, it's usually not a good idea. Here's why it's not working.. A switch statement compares the value in it's parameter to each case, if it's true then that case fires. Because you're usnig $ttest it compares (for example) $ttest to $ttest > 49 && $ttest < 50. The statement '$ttest > 49 && $ttest < 50' will evaluate to either true, or false. You want the case to fire if it's true. But when $ttest is 0 it's basically trying to compare false (because 0 == false) to the statement, giving you the exact opposite of what you want. Here's what happens: $ttest = 0; switch ($ttest) { case ($ttest < 50): // $ttest < 50 evaluates to true, but you're comparing this true, to $ttest, and since $ttest == 0 == false you're getting: true != false so it goes to the next statement.. $ttestr = "<div>Get at least 50 credits</div>"; break; case ($ttest > 49 && $ttest < 500): // Here you're getting false for '$ttest > 49 && $ttest < 500' and $ttest is == 0 == false, of course, false == false. which is why this one is triggering. $ttestr = "<div><b>RANK 1</b></div><div style='color: #d00000; font-size: 10px;'>You have <b>".$ttest."</b> credits</div>"; break; case ($ttest >= 500 && $ttest < 5000): $ttestr = "<div><b>RANK 2</b></div><div style='color: #d00000; font-size: 10px;'>You have <b>".$ttest."</b> credits</div>"; break; case ($ttest >= 5000): $ttestr = "<div><b>RANK 3</b></div><div style='color: #d00000; font-size: 10px;'>You have <b>".$ttest."</b> credits</div>"; break; } Long story short, you can just use switch(true){...} instead of switch($ttest){...} to get the functionality that you're looking for. Although, I'd go for an if.. else if.
  11. Just use count() and array_sum. Like so: echo array_sum($arr) / count($arr);
  12. How do you expect that to work? Not all words are the same length.
  13. or if(((((((strlen($msg)>=20)))))) && ((((((strlen($msg)<=200)))))))
  14. You're taking thrope's comment way to seriously. It wasn't even directed at you, he was just making a joke. Learn to take a joke dude.
  15. You have it backwards.. if(strlen($msg)>=20 && strlen($msg)<=200)
  16. I can see how that would be annoying. There are some websites out there that offer colors/palettes that look nice. Granted it might be harder for you to determine was is 'nice', but at least they can help you get some decent colors that go together. One such website is http://www.colourlovers.com/
  17. You're gonna want to use preg_replace_callback(). Something like this should work: $pr->postDesc = preg_replace_callback("/\[code\](.+?)\[\/code\]/is", create_function('$matches', "return '<pre class=\"codeprint\">' . htmlentities($matches[1]) . '</pre>';", $pr->postDesc);
  18. Array() isn't a function. It's a language construct, there's really no benefit to doing it either way, for the most part it's just different ways of doing things. But say you're putting 10 objects into an array, it would be easier to use the Array() language construct than to rewrite $array['index'].. 10 times.
  19. Make your colors more user-friendly, my eyes hurt.
  20. If you want to sort the thing entirely, and not just each segment then you'll have to create an array containing all the elements at once. You can do this by using array_merge() in each iteration of your current loop, then perform asort() on that array. Then you can loop through the entire [sorted] array in a similar fashion as to how you are now to create the table structure.
  21. Check the manual, mysql_insert_id() doesn't take a mysql query resource as a parameter. It takes the mysql connection link, which is only an optional parameter. Just try: $insertID = mysql_insert_id();
  22. Here's a basic example: <?php $text = <<<EOT Some text here <b>Replace This</b> Some text here Some text here EOT; $text = preg_replace_callback('~<b>(.+?)</b>~', create_function('$matches', 'return "REPLACED!";'), $text); echo $text; /* Output: Some text here REPLACED! Some text here Some text here */ In this example we're replacing any <b></b> tags and their contents with "REPLACED!" inside of text. Note that parameter 2, as of PHP 5.3, can be replaced with an anonymous function like so: $text = preg_replace_callback('~<b>(.+?)</b>~', function($matches){ return "REPLACED!";}, $text); Edit: I might have misunderstood your original problem. If you don't need to edit the match of the regular expression based on the match (an example would be just strtoupper()'ing the match) then you're best off just using preg_replace().
  23. Sounds like you're going to want to use preg_replace_callback() instead. That way you can search a string for something, get the result then inside your callback function you can process and do whatever you want with the matched. If you need an example feel free to ask.
×
×
  • 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.