Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. More often than not you can find what you need to know in the manual, and if somewhere else online. http://php.net/manual/en/language.oop5.visibility.php As it states there, public methods and properties are accessible from outside of the object and private one's aren't, basically. class Foo { private $_var = 'value'; public $var = 'value'; public function __construct() { ... } } $instance = new Foo(); echo $instance->var; // Can access this property since it's public echo $instance->_var; // Can't access this property because it's private
  2. In your example there would be no benefit. If you don't know the benefits of using OOP you shouldn't be using it because you won't be getting anything out of it anyway. You can easily find a lot of material about OOP so if you're really interested I suggest you read up on it. You can start here.
  3. Well, that kind of works. It's too strict, I don't want it to be a requirement that both variables names and values must be there. Just that optionally, up to 2 can be displayed. Also, using this method breaks all relative links, in a case like this would it just be standard to make everything utilize absolute paths?
  4. I'm trying to rewrite something like: file.php?var=val&var2=val2... to: file/var/val/var2/val2... I'm also using the rewrite rule below to redirect site.com to www.site.com. I've tried a few things, but I can't seem to get it working correctly. RewriteEngine On RewriteCond %{HTTP_HOST} !^www.rakugumi.com$ RewriteRule ^(.*)$ http://www.rakugumi.com/$1 [R=301]
  5. http://us.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
  6. Well that's because you're storing your alerts in an array. Use implode to convert it to a string. echo implode("<br />\n", display_alerts());
  7. You're never echoing what's returned from the function. echo display_alerts();
  8. <?php readfile('path/to/file.png'); header('Content-type: image/png'); That PHP script outputs an image, you can add whatever you want to it. If you need an image extension you can change the file to *.png (or any other image extension) and use .htaccess to have PHP interpret that file.
  9. You should be using < not <=. for($x=0;$x<$linecount;$x++)
  10. You better let the people working in quantum physics know about this, they have it all wrong.
  11. If you view the source of the output you'll see it is as expected. You're looking for HTML <br /> line breaks. If you want the print_r to display the line breaks in html as well, use the second parameter in print_r to return the output and then perform nl2br on that to convert character \n to <br />. echo nl2br(print_r($a, true));
  12. <?php $arr = array( 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E' ); unset($arr[2]); print_r($arr); unset
  13. Do you have the path correct?
  14. Well then that means your news.txt file contains nothing. To fix this before reading from the make sure there's actually something to read, like so: <?php if(($filesize = filesize('news.txt')) > 0) { $fp = fopen("news.txt","r") or die("Cannot open"); $file = fread($fp, $filesize); fclose($fp); } ?>
  15. To prevent mysql injections you should pass all data through mysql_real_escape_string before it's inserted into the query.
  16. Your problem is that fopen does not return the content of the file, so $file won't contain what you're expecting. Instead to you need to use fread. If you want to get the full content of the file you can do something like this: <?php $fp = fopen("news.txt","r") or die("Cannot open"); $file = fread($fp, filesize('news.txt')); fclose($fp); ?> The problem with your updating is that for fwrite you need to pass the resource returned by fopen ($file, in your case). <?php $content = $_POST["content"]; $file=fopen("news.txt","w") or die("Cannot open"); fwrite($file, $content); fclose($file); ?>
  17. If you want to nitpick that's a valid img tag either. In the img tag the alt attribute is required, and if it's XHTML it must self-close.
  18. I've personally tested installing windows 7 on a machine that was running windows XP. This machine was equipped with half of the minimum "required" RAM (1GB) to run Windows 7, 512MB. It ran fine, in fact I would have to say that it ran smoother than windows XP did on the very same machine. More functionality, better usability and aesthetics, I'd say there are many reasons to upgrade.
  19. There's no $ in front of the variable name. Just: $this->arrayName[0];
  20. mysql_fetch_assoc, as the name suggests, returns an associative array. You might be looking for mysql_fetch_row.
  21. You can do it like this (basically): $str = 'one two three four five six seven car eight nine ten eleven twelve thirteen fourteen fifteen'; $words = str_word_count($str, 1); $index = array_search('car', $words); echo implode(' ', array_slice($words, $index - 5, $index + 4)); That's just an example, you should really be doing more checking to make sure that the word you're searching for is found, and that there are 5 words on either side of the word if it is found.
  22. var input = "my name is james from canada x"; alert(input.substr(0, input.length - 1));
  23. You're missing a closing ) on this line: while ($row = mysql_fetch_assoc($result) Should be: while ($row = mysql_fetch_assoc($result))
  24. Try: imagejpeg($image, null, 100); To set it to the highest quality.
  25. A quick Google search returned this, you can try that.
×
×
  • 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.