Jump to content

oni-kun

Members
  • Posts

    1,984
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by oni-kun

  1. I don't know what you mean exactly. I would text that code right now but I don't really feel like configuring it for my site right now I'll do it in the morning, but does that mean that there will or will not be any blank lines with that code? You're not aware of whitespace? Take this line i'm writing now for instance The actual line in code is 'Take this line i'm writing now\n for instance'. That is why exploding \n will return all the lines. \n is the equivalent of pressing 'enter'. OS's just takes it and displays a return in place. So yes, if you remove the \n return, it will not display a line (so the blank line would disappear).
  2. Yeah it would look like that, and be called through $_POST['deleted'] With the physical '\n' removed from the line, it will not show up as a blank line on the outputted page, as without the return it will just 'collapse'.
  3. $file = 'I \n am \n a \n line \n number did you \n know \n this? \n \n'; $lines = explode('\n', $file); for ($i=0;$i<=(count($lines)-1); $i++) { echo ($i+1) . "." . $lines[$i] . "\n<br/>"; } $delete = explode(',' , '1,2,3,4,5'); for ($i=0;$i<count($delete);$i++) { $lines[$i] = ""; } Rough method, but it will list something like: The user can enter the lines they want deleted into the text box, $deleted can be the $_POST value (for ease) of it. Anc after the said lines are deleted (with the example code): So if $deleted was '1,2,3,4,5' : Then you can use implode and file_put_contents to put the file back. No \n means that the line will disappear, and not show in the result file.
  4. You can do it your method, but it is not such a good idea as it will require much more than a form, but a database. fgets / file_get_contents can pull out the file, to get each line you can simply explode it. $file = file_get_contents('file.txt'); $lines = explode('\n', $file); unset($lines[22]); //22'nd line. foreach ($lines as $line) {{ echo $line; //Display all lines. } Each will fill it's own array item, so you can do what you want with it, array search text you don't wish etc.
  5. Escapes are your friend, when you do not want to convert. $command = "\255\x\x\x\x\x\x\x\x\x\x\x\x\4";
  6. #3: "Please read the documentation on preg_match_all to view the available parameters. Also check this tutorial out! http://ca2.php.net/manual/en/function.preg-replace-callback.php" Meh, thought it'd look worse. EDIT: The sun is reflecting off that font, Oh god!
  7. "As you would an image path", Normally they are defined relative to the current file, What are you going on about it creating an error? include('/http://site.com/image/script.php'); Will obviously produce an error. As for relativity the slash is not even needed unless you require recursion. As for "How it effects load time." Do you want to assign the 0.2MS to your server or their browser for path calculation?
  8. You can see with the syntax highlighter on your example, why it will not work. The string ends. You must escape all metacharacters.
  9. I prefer links in browser specified colours. EDIT: Thank goodness #2 is closest to the real colour, see? If it's the de-facto for 50 years...
  10. This feature is in place for users to not be able to modify their posts after a specific period of time, namely to prevent someone to replace their post with '[solved]' when they've found their answer. This preserves temporal indexing. I've not run into any problems when posting a thread with this, if you need to add something than if the time is up it's worth it to bump your thread anyway.
  11. $this is a reserved variable in most styles of code (originated from the programming language C) that returns the current class or object. 'this' is a reference to 'this object' or 'this scope' Sometimes it's necessary to retrieve the value of $this from within an object. This solution dedicates a public var $ID to store a unique identifier for the object: <?php class Someclass { public $ID; public function what_is_this() { return '$this is: ' . $this->get_varname(); } private function get_varname() { $this->ID = uniqid(); foreach($GLOBALS as $key => $val) { if (is_a($val,'Someclass')) { if ($val->ID === $this->ID) { return $key; break; } } } } } // example: $my_var_instance = new Someclass; echo $my_var_instance->what_is_this(); // returns '$this is: my_var_instance' ?> In Visual BASIC style coding conventions, the variable is called 'me', and is referenced such as: 'me.title = 'Foobar'; '
  12. You'd use a foreach loop. Here's a rough example: $array = array('http://1.com' , 'http://2.com' , 'http://3.com'); foreach ($array as $arr) { //Curl code for $arr echo $arr; } Notice it lists the array each loop, so you can easily get CURL to execute 3 times.
  13. That is what you'd call a relative URI. You would need to do nothing, as it simple includes it from the path. Such as './contactUs.php' , it doesn't need a host name.
  14. I was going to mention this but forgot. Anyway, Like this: $host = $_SERVER['HTTP_HOST']; echo "http://$host/folder/test.html"; //http://127.0.0.1/folder/test.html or http://site.com/folder/test.html That will display the correct host, in development or live environment. For your reference I'd look at this: http://www.php.net/manual/en/reserved.variables.server.php It will list all the $_SERVER variables which may become handy to you over time.
  15. Yes, the current page you are viewing is a file to be included. If it isn't defined then this is obviously so.
  16. How can you record the amount of users with no database? Lets say you store a session for each user that logs in, there's no way to correlate how many users there are purely based on them. You can, however use a hack method. <?php session_start(); function getUsersOnline() { $count = 0; $handle = opendir(session_save_path()); if ($handle == false) return -1; while (($file = readdir($handle)) != false) { if (preg_match("/^sess/", $file)) $count++; } closedir($handle); return $count; } ?> That is , however theorietical code. I'm sure there's other ways you can store the user count in, such as a flatfile (usercount.txt). As for your session expiry, there's not a method to singulate a user after the session has already ended. (without any further details on what you're exactly doing)
  17. Then he'd ask for that solution. For just sorting, those tools are VERY clean, simple, and easy to manage. I'm sure as all his relevant code, example references of what he wants to do.. Had nothing to do with PHP at all. You're right, he didn't ask specifics
  18. What if he needed to export the table order in a specific way to anything? Teaching him JS to do something SQL can do is rather, backwards in the order of effectiveness in programming.
  19. Generally JS->SQL is a bad idea. Although it fits what he's trying to do, he's wanting to sort it serverside rather than client side.
  20. Yup. If you're still learning, than you can easily echo HTML or close the tags for php and insert the value manually like so: <td height="21"><?php echo $cal; ?> Issue Charges</td> <td><div id="txtcharges"></b> </div></td> Or you can simply define it within a string, where the HTML is supposed to show up: echo '<td height="21">' . $cal; . ' Issue Charges</td> <td><div id="txtcharges"></b> </div></td>'; //echo HTML as a string with $cal. Pass the values to the other page through include/sessions.
  21. I was tired but re-read this in spare time, I couldn't stop laughing! It's always interesting to run into those people, who are so fixated on something they will not listen to any logic no matter what
  22. I'd recommend against teamatomic's solution. But what you should do is use a database if you're looking for a serious solution, and call it through $pageid = (int)$_GET['page']; to tighten security and manage easier. If you're wanting to keep it simpler, it'd be much easier to do it in your first method.
  23. What about the PHP version? It's funny, my old host bumped me down to 4.3 for some reason.. safely to say I moved. If PHP is run as a module than you're able to change, atleast some settings with .htaccess, such as open_basedir.
  24. <?php $_POST['foo'] == 'bar'; echo $HTTP_POST_VARS; ?> What do you get if you run this? If $HTTP_POST_VARS comes up as an undefined variable, than register_globals is off. @TeamAtomic, It's already been stated that PHPinfo was off. EDIT: <?php echo 'Current PHP version: ' . phpversion(); ?> That should help as well.
  25. Hmm.. I've heard shared hosts disabling this to disallow the user to view configuration (paths etc.). If they've gone this far to protect themselves, than I believe that the host isn't worth their salt.. Anyway, why not try a global and test? $HTTP_HOST for example.
×
×
  • 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.