Jump to content

Daniel0

Staff Alumni
  • Posts

    11,885
  • Joined

  • Last visited

Everything posted by Daniel0

  1. What's your HTML?
  2. Read the post before yours:
  3. Does phpinfo() say that Zend Optimizer is installed?
  4. Not really, as long as it's valid syntax, but if you can do what corillo181 says (I didn't bother to check), then you might as well do so. I just realized that I talked to you (corillo181) about you in third person...
  5. Not really, as long as it's valid syntax, but if you can do what corillo181 says (I didn't bother to check), then you might as well do so.
  6. This: $person['name'][ceil((strlen($person['name'])-1)/2)]; is what gets the middle character, and to get it like you want it then it'll be: $person['name'][floor((strlen($person['name'])-1)/2)]; To understand how it works we'll split it up... You take the length by saying strlen($person['name']). Then you subtract 1 from it since we'll be working with the string as an array and the indexes in an array is starting from 0 and not 1. So we have strlen($person['name'])-1. Then we'll divide it by 2 to find the character in the middle. That means if the name was Daniel then we will have 2.5 now. There is no 2.5 character so we use floor() to round it to the next lowest integer which is 2 (or, well... the position of the middle character). So now we know that 2 is the middle character so we simply get the character by accessing the string as an array: $person['name'][floor((strlen($person['name'])-1)/2)]; or in this case: $person['name'][2]; You could write it like this as well: <?php $name = 'Daniel'; $string_length = strlen($name); $var = $string_length-1; $middle_character_pos = $var/2; $middle_character_pos = floor($middle_character_pos); $middle_character = $name[$middle_character_pos]; echo $middle_character; // output: n ?> But this is much shorter: <?php $name = 'Daniel'; echo $name[floor((strlen($name)-1)/2)]; ?> Using the string $name you could output Daniel in the following way: <?php $name = 'Daniel'; echo $name[0].$name[1].$name[2].$name[3].$name[4].$name[5]; // OR for($i=0; $i<=strlen($name)-1; $i++) { echo $name[$i]; } ?> because you can access strings like arrays. (you shouldn't do that however - it would be stupid)
  7. That because (as I said) it is an array. Do print_r($_GET['lang']); to see and you can use d22552000's code to iterate through it (providing you send it via GET).
  8. Does it really matter? It's just whitespace. If you want it like that, then you can use tidy though. You do apparently not understand the code he posted.
  9. Around the entire variable. <?php $rand = rand(); echo <<<EOF <html> <head> <title>LOGGED IN - Student Tabulation - Login ID {$rand}</title> </head> <body><p> <font color="red" face="trebuchet ms" size="8"><strong>Warning</strong>: Advanced Logging Enabled</font> <br /></p><p> EOF; mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db("Rolla High School") or die(mysql_error()); $sql = "SELECT * FROM 'teaid' WHERE `TEAID` = '{$id}'"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($res, MYSQL_ASSOC)) { echo <<<EOF <form action="index.php" method="GET"> <input type="hidden" name="id" value="{$id}"> <input type="hidden" name="pw" value="{$pw}"> <input type="hidden" name="s" value="3"> <select name="clsid"> <option value="{$row['clsid1']}">{$row['clsid1']}</option> <option value="{$row['clsid2']}">{$row['clsid2']}</option> <option value="{$row['clsid3']}">{$row['clsid3']}</option> <option value="{$row['clsid4']}">{$row['clsid4']}</option> <option value="{$row['clsid5']}">{$row['clsid5']}</option> <option value="{$row['clsid6']}">{$row['clsid6']}</option> <option value="{$row['clsid7']}">{$row['clsid7']}</option> <option value="{$row['clsid8']}">{$row['clsid8']}</option> </select><input type="submit" value="submit"> </form> EOF; } echo <<<EOF </p> </body> </html> EOF; ?> You did in the code you posted
  10. Use heredoc and put the variables in curly brackets then.
  11. Name them like this: Which of the following languages do you speak?<br /> <input type='checkbox' name='lang[]' value='en' /> English<br /> <input type='checkbox' name='lang[]' value='es' /> Spanish<br /> <input type='checkbox' name='lang[]' value='fr' /> French Then you can access it like $_POST['lang'] or $_GET['lang] which will be an array containing the selected languages.
  12. Third argument of setcookie() specifies when the cookie should expire. http://php.net/setcookie
  13. Replace the `s with 's. (not in the query but e.g. $row[`clsid2`] should be $row['clsid2'])
  14. None. It's just (IMO) better to separate things (HTML, CSS and Javascript) though.
  15. HTTP/1.1 403 Forbidden (I think)
  16. Hmm... are we talking about WYSIWYG editors for your website or for creating websites?!
  17. Try to use mysql_error() to find out what the MySQL error is.
  18. Could this be the reason? [attachment deleted by admin]
  19. Please don't post your topic in bold. Would something like this do it? <?php $people = array( array( 'name' => 'Peter', 'age' => 30, ), array( 'name' => 'Mary', 'age' => 35, ), array( 'name' => 'Michael', 'age' => 22, ), ); class PeopleSorter { private $people = array(); private $sorted = array(); public function __construct(array $people=array()) { $this->people = $people; $this->sort(); } private function sort() { $middle_chars = array(); foreach($this->people as $person) { $middle_chars[] = $person['name'][ceil((strlen($person['name'])-1)/2)]; } $this->sorted = $this->people; array_multisort($middle_chars, $this->sorted); } public function get_sorted() { return (array) $this->sorted; } } $people = new PeopleSorter($people); echo "<ol>\n"; foreach($people->get_sorted() as $person) { echo "\t<li>{$person['name']}, {$person['age']}</li>\n"; } echo "</ol>\n"; ?> Output will be: <ol> <li>Michael, 22</li> <li>Mary, 35</li> <li>Peter, 30</li> </ol> Edit: Note: If the name has an even number of characters (e.g. Daniel which has six characters), then it will take the right-most middle character. E.g. the middle character in "Daniel" would be 'i'. Edit 2: I didn't really get why you said "using OOP". What does the actual work is PeopleSorter::sort(). The reason why I made the class is because you specifically said "using OOP".
  20. What are you trying to do?
  21. You could use FCKeditor or TinyMCE. What's the point in indenting what you are saying?
  22. Yes.
  23. MD5 is one-way so there is no way to decrypt it.
  24. wildteen: You can use array for type hinting as well.
  25. You cannot use classes instead of functions. They are not the same and do not have the same function. Try to read: http://php.net/language.functions http://php.net/oop5
×
×
  • 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.