Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by doug

  1. Thanks. That did work! I sort of see why and also don't see why. I thought that RegExp was supposed to take a string and turn it into a regular expression. \d only has one interpretation in a regular expression - a digit. So I thought that was ok as is. In fact, I would have guessed that \\d+ meant "find a backslash, the letter d and a plus sign."But anyway, I'll just try to remember to escape all my backslashes in RegExp from now on.You are right, of course, about \-, but I tend to escape all my punctuation so I don't have to remember which has special meaning and which doesn't.Thanks!doug
  2. This truly is a simple regular expression question. :)I have a variable theTitle with the value: "Test Group A BTYZ311-1"And a variable courseCode with the value "BTYZ311".I want to see if theTitle contains courseCode followed by a dash followed by 1 or more digits.This is my test: var matchExp = new RegExp(courseCode + '\-\d+', "i");if (!matchExp.test(theTitle)) { // do something because theTitle doesn't seem to contain the courseCode plus dash + number} The problem is the .test() method always returns false, so there must be something wrong with my RegExp.Does anybody happen to see what that might be?Thanks,doug
  3. There is no one server-side JavaScript, but the basic idea is that it is the same language, with all the core JavaScript methods and properties: String, Date, Objects, prototyping, etc. In our case, it interacts with a native object-oriented server-side database so you can use extended methods to do things like create new users, new discussions and folders and other kinds of objects for storing in the database.Naturally server-side JS is not aware of the client, so, for example, there is no "document" object to work with. Similarly client-side JS is not aware of the server-side database.The server-side JS can dynamically generate web pages, similar to how PHP does it. And the generated pages might have client-side JS in them.It's an alternative to PHP in some sense. I prefer it to PHP because JavaScript is such a rich, flexible language and you don't have to deal with two languages for development. But unfortunately it is not standard at all, or that wide spread.But in our system it works very well. It's also compiled on the server side so it's very fast.doug
  4. I've been using JavaScript, both client-side and server-side, for years. I never noticed this before though. Here is a quick client-side example: <html><script>var a = new Object();a. b = 'testing';document.write(a.b);</script></html> The above page opens and runs without complaint in at least Safari and FireFox. The equivalent in my server-side JS also compiles without error and runs fine.But... notice the extra space after the period, before the property name, in the a. b = 'testing'; line. Why doesn't that space cause a problem?Just curious.doug
  5. Ah. Well, that explains it. Thanks.doug
  6. Thanks. file_get_contents() does work. I am still curious about the http_get() function though, described at http://jp2.php.net/manual/en/function.http-get.phpThanks,doug
  7. The following very trivial (I thought) http_get() test fails: <?php$body = http_get('http://www.nytimes.com');echo $body;?> The error returned is:Fatal error: Call to undefined function http_get() in /home/doug/public_html/inpac/tests/httpRequest1.php on line 3I found http_get in the online PHP manual. Is it not a global, standard function?Thanks,doug
  8. In this example from the book I'm reading: <?$im = ImageCreateTrueColor(256,60); for($x=0; $x<256; $x++) { ImageLine($im, $x, 0, $x, 19, $x); ImageLine($im, 255-$x, 20, 255-$x, 39, $x<<8); ImageLine($im, $x, 40, $x, 59, $x<<16); } header('Content-Type: image/png'); ImagePNG($im); ?> three color bars are drawn.I understand the calculations in the last parameters of ImageLine. They look like the 32 bit r,g,b,alpha (with anti-aliasing flag) values that would be returned from imageColorResolveAlpha.But why wasn't it necessary to call imageColorAllocateAlpha to begin with to establish the colors for the image? Are calls to imageColorAllocateAlpha only needed if overriding some automatic default table?If so, does that hold true for imageColorAllocate and imageColorResolve as well?This book (the O'Reilly book "Programming PHP 2nd Ed" is sure skimpy on details in a lot of places!doug
  9. In the book I'm reading there is the following example, which works. Let's say this is in button.php: <?php $font = 'times'; if (!$size) $size = 12; $im = ImageCreateFromPNG('button.png'); // calculate position of text $tsize = ImageTTFBBox($size,0,$font,$text); $dx = abs($tsize[2]-$tsize[0]); $dy = abs($tsize[5]-$tsize[3]); $x = ( ImageSx($im) - $dx ) / 2; $y = ( ImageSy($im) - $dy ) / 2 + $dy; // draw text $black = ImageColorAllocate($im,0,0,0); ImageTTFText($im, $size, 0, $x, $y, $black, $font, $text); header('Content-Type: image/png'); ImagePNG($im); ?> The text parameter is passed in the URL as follows:http://thedomain.com/button.php?text=the+buttonMy question is, why does this work? Why didn't I have to have a line:$text = $_GET['text'];in order to grab the parameter from the URL?Isn't it dangerous to allow variables to just be set like that in the URL?doug
  10. Thanks, I'll take a look at the Wikipedia article. doug
  11. I'm not about to actually attempt a project that requires large scaling, but was wondering, just in general, what sites with massive scaling (like hundreds of thousands or even millions of users) do to achieve that?I assume a large part of the problem is the database. At some point, if all your SQL requests are made to one database on one server things just get to busy with requests to serve well.Is one way this is handled by breaking things up into multiple databases, and serving different databases on different servers?Like consider user records. Instead of keeping all the users in one big database, do larger projects employ strategies such as keeping all A users in one database, the B users in another, etc?For something like a large forums server, instead of storing all the tables for the forum content and all the tables for users records in one database, is there an advantage to storing the forums content in one database and the user records in another database?I'm just curious about the practical limitations of a single database and when you should consider breaking it up into multiple databases.Thanks,doug
  12. In my PHP database experiments so far, I've been using MySQL. It's all worked fine. I use cPanel at my ISP to create databases, set up the connections in PHP and everything works ok.In the O'Reilly book I've been reading, "Programming PHP 2nd Ed", in the chapter on databases, the author first suggests using the PEAR DB abstraction layer for the purposes of portability.At the end of the chapter, he describes another abstraction layer, PDO (PHP Data Objects) and says it should be available "by the time you read this" and listed some benefits over PEAR DB.What do most PHP programmers do these days? Just make MySQL calls directly? Make use of PEAR DB? Make use of PDO? I know that Ruby on Rails always uses database abstraction layers for maximum portability, and the idea seems like a good one. But what is really done in common practice?Also, the author mentions that SQLite is bundled with PHP. Is there any reason to prefer using that over MySQL?What are you thoughts?Thanks,doug
  13. I've been going through the O'Reilly book "Programming PHP". In the section on object constructors, there seems to be a mistake and I wanted to get your opinions of it. The section says: A constructor is a function in the class called __construct(). Here’s aconstructor for the Person class: class Person { function __construct($name, $ag‘e) { $this->name = $name; $this->age = $age; } } PHP does not provide for an automatic chain of constructors; that is, if you instanti- ate an object of a derived class, only the constructor in the derived class i sautomati- cally called. For the constructor of the parent class to be called, the constructor in the derived class must explicitly call the constructor. In this example, the Employee class constructor calls the Person constructor: class Person { var $name, $address, $age; function Person($name, $address, $age) { $this->name = $name; $this->address = $address; $this->age = $age; } } class Employee extends Person { var $position, $salary; function Employee($name, $address, $age, $position, $salary) { $this->Person($name, $address, $age); $this->position = $position; $this->salary = $salary; } } But in the example, a function __construct() is nowhere to be found. Is this an error, or can a function the same name as the class itself be used instead of the function name __construct?Thanks,doug
  14. There also appears to be commercially available solutions for this, such as:http://www.sourceguardian.com/doug
  15. Thanks. That looks like one possible way to go. It seems to be a partial, and also out-dated solution (doesn't support PHP 5) and is not maintained any more. But it is useful to know that there has been some thought to this.doug
  16. I understand that the server itself is executing the PHP and just sending client-side results to the browser. And as long as a file's extension is .php and the end-user doesn't have file system access to the source they can't see the PHP code itself.But what about the case where you are developing code for a customer who does have file system access (so they can upload their own web pages and images, etc.) Or if you develop a program for a customer to run on their own server?Is there any way of protecting your PHP source code from possible theft in cases like that? Like source file encrypting or something?Thanks,doug
  17. It's impressive that it works as well as it does as an interpreted language that needs to "start from scratch" basically for each page that is loaded!doug
  18. I'll check those out, thanks. I was more worried about speed than memory. How does a place like Facebook deal with that? Do they use a special "compiled once" version of PHP or is it the same PHP that everybody else uses? Do they just serve off of a zillion servers?doug
  19. Speaking of including things on every page - do people tend to build an entire library of functions that are loaded on every page regardless of whether they are used on that page or not? Or do people tend to build sets of library functions that are loaded on different pages according to use?One thing about PHP that is different from the server-side JavaScript I've been using is that I had a bunch of huge source files that were compiled once and could then be used anywhere. But with PHP everything gets re-parsed and then interpreted for every single page that is loaded, right? I'm amazed that this isn't an overwhelming burden on the server.doug
  20. In the "PHP Programming" book I'm reading, there is the following working example: <?phpfunction count_list() { if(func_num_args() == 0) { return false; } else { for($i = 0; $i < func_num_args(); $i++) { $count += func_get_arg($i); } return $count; } } echo count_list(1, 5, 9);?> Something similar in JavaScript would cause an error at the $count += statement because it had not been initialized.Is this considered ok programming practice in PHP - to not initialize variables before you start to += to them?doug
  21. I saw this example in the PHP book which also struck me as being sort of awkward syntax: <? function column() { ?> </td><td> <? } ?> It seems that rewriting this as follows is easier to read, don't you think? <? function column() { echo '</td><td>';?> I guess if there are MANY lines of HTML in the function that the first format might be easier in that case.doug
  22. Thanks. That sounds like a good way of thinking about it.doug
  23. I guess I'm semi-happy that it "works" that way. It seems counter-intuitive though. Maybe not. Certainly in a client-side sense something like that happening with client-side JavaScript would be way bizarro. But on the server-side I suppose the parser can do what it likes.But rather than "stopping and starting" the PHP blocks, it seems it would have been neater to just have some sort of "literal" syntax. For example, in your example, it would be easier to write and read if it was something like:<?phpif ($var) {<literal>$var is true</literal>}else {<literal>$var is false</literal>}?> At least you would know you were still inside PHP while reading through the code.But it is an interesting syntax thing to be aware of. Thanks.doug
  24. hostgator.com will not screw you over. I can't recommend them highly enough. I actually use their "Swamp" level service, which is just $14.95 a month because I have a bunch of domains that I need to do things like provide home pages and email for.They are reliable and their service could not be better. They have 24/7 support via email, telephone or live chat. I have been using them for well over a year now and have never had a problem. When I started playing with PHP I had a question about setting it to be PHP 5 instead of PHP 4 and went into Live Chat and they helped me out right away.My only fear is whether they can keep their level of service at such low prices!doug
  25. This example in the O'Reilly "PHP Programming" book shows the use of an alternate block if syntax: <?if($user_validated):?> <table> <tr> <td>First Name:</td><td>Sophia</td> </tr> <tr> <td>Last Name:</td><td>Lee</td> </tr> </table> <?else:?> Please log in. <?endif?> I understand the code, but I don't understand why it works. The if, else and endif statements are all "out there by themselves" outside of the HTML. Why does one section of the HTML get sent by the server if true and the other part if false? Since ALL the HTML is outside the PHP scripting brackets, why doesn't ALL the HTML get sent by the server?Thanks,doug
  • Create New...