ShawnCplus 456 Code Monkey Team Colleague

"/^(\d{1,7})\.(\d{1,2})$/" If you're testing a string you want to set the anchors "^" (beginning of string) and "$" (end of string) so you know that there is nothing else in between. "/(\d{1,7})\.(\d{1,2})/" will match 12345678.12 because it is matching, take a look at this.

without ^$
  __________
1|2345678.12|
  ----------
that's 7 numbers a decimal and 2 numbers, so a match
with anchors
 _______
|1234567|8.12
 -------
no match
ShawnCplus 456 Code Monkey Team Colleague

Wow thanks so much for that. I thought you meant an actual abstract class, i.e:

abstract class foo {...}

One question though.. is there any significance behind the values of the constants or did you just arbitrarily pick them?

Thanks again.

Well, arbitrary in the sense that they aren't language constants but I picked the names because their purpose is easy to determine.

ShawnCplus 456 Code Monkey Team Colleague

You might want to use grep for that, use can use it inside vi/vim with the ! command
:!grep funcname <dir>

ShawnCplus 456 Code Monkey Team Colleague

The first one looks like a declaration of a vector of ints of size alpha, if alpha is an int---or something that acts like an int. The second parameter to the constructor has the default value.

I have no idea what the second is attempting to do. Wild guesses might be a copy constructor or 2 dimensional vector of ints. If it's valid, it's nothing I've seen before and it's not something I could find in my reference. My reference does give this as a copy constructor:

vector<int> v(v2);

for a vector of ints where v2 has already been declared as type vector<int>, if I interpret my reference correctly. The actual version in my reference looks like:

vector <T> (const vector& c);

I don't see how you could declare both the vector you want to copy into a new vector and the new vector at the same time, as it seems to be trying in the OP, however.

At first I thought initializations of constructor/copy constructor but it looks more just like function prototypes.

ShawnCplus 456 Code Monkey Team Colleague

Actually, it is a normal vector declaration. std::vectors are a templated class. To instantiate a vector you pass a type to the template. Might want to read up on templates. In this case the code looks to be function prototypes. The first function returns a vector of int's and takes alpha which I'm assuming is a user-defined type. and the second is an overload of the same function to take a vector of ints.

ShawnCplus 456 Code Monkey Team Colleague

thanks for the advice

so using the first example:

if [0] had [a][c]

all i'd need to do to access an array and assign the contents to vars would be (using first example):


$avar = $somearray[0]['a'];
$bvar = $somearray[1]['b'];

echo $avar;
echo $bvar;

// Hello
// World

Precisely. If you want to get really deep into how arrays work take a look at the language documentation. http://php.net/arrays

ShawnCplus 456 Code Monkey Team Colleague

What's the error? "standard error" doesn't help.

ShawnCplus 456 Code Monkey Team Colleague

Or you could just write the method for (in your example) Person to change the name themselves. ie., person->setName() There is absolutely no need for a "superclass". Their true name is "god class" and it's referred to as an anti-pattern. They are the bane of good OOP principles. Don't make them. Just don't.

There is absolutely no reason you can't do

$person = new Person($somepersonid);
$person->setName('Tester');

You could make the database access inside the Person constructor, it doesn't have to be in the GUI. I'm not entirely sure where you're getting this mindset.

ShawnCplus 456 Code Monkey Team Colleague
$somearray = array(
  array('a' => 'Hello'),
  array('b' => 'World')
);

echo $somearray[0]['a'] . ' ' . $somearray[1]['b'];
// Hello World
ShawnCplus 456 Code Monkey Team Colleague

If I had to pick four of the best I'd say Zend, Symfony, CodeIgniter and Cake. Zend is a pretty in-depth and heavy framework. Symfony is lightweight but also quite powerful with a huge community, amazing documentation (a book is published for every version). Cake is even lighter but also has a pretty large community and die-hard fans. CodeIgniter is probably the lightest but I'm not too familiar with it so I can't give you a big review on it.

If I had to pick one I'd say Symfony if only because I'm familiar with how easy it is to pick up and its crazy-fast turnaround time for projects but take a look at that list and see which one fits your needs.

ShawnCplus 456 Code Monkey Team Colleague

I'll give you a pretty advanced example for the sole reason for you to learn from.

<?php
class Request
{
  const TYPE_NONE   = 0;
  const TYPE_ALPHA  = 1;
  const TYPE_DIGIT  = 2;
  const TYPE_ALNUM  = 3;

  const GET         = 10;
  const POST        = 11;
  const COOKIE      = 12;
  const SESSION     = 13;

  public static function get($name, $method = null, $validation = null)
  {
    if ($method < self::GET && $validation === null) {
      $validation = $method;
      $method = self::GET;
    } else if ($method === null ) {
      $method = self::GET;
    }

    if ($validation === null) {
      $validation = self::TYPE_NONE;
    }

    $holder = null;
    switch ($method) {
      case self::GET:
        $holder = $_GET;
        break;
      case self::POST:
        $holder = $_POST;
        break;
      case self::COOKIE:
        $holder = $_COOKIE;
        break;
      case self::SESSION:
        $holder = $_SESSION;
        break;
    }

    if (!isset($holder[$name])) {
      return false;
    }

    $validator = null;
    switch ($validation) {
      case self::TYPE_ALNUM:
        $validator = 'alnum';
        break;
      case self::TYPE_DIGIT:
        $validator = 'digit';
        break;
      case self::TYPE_ALPHA:
        $validator = 'alpha';
        break;
    }

    $ret_val = $holder[$name];
    $valid_func = 'ctype_' . $validator;
    return (($validator === null) ? $ret_val : (( $valid_func($ret_val) ) ? $ret_val : null ) );
  }
}

USAGE:

// basic GET param with no validation
$blah = Request::get('blah');
// GET param with validation
$blah = Request::get('blah', Request::TYPE_DIGIT);
// POST param
$blah = Request::get('blah', Request::POST);
// POST param with validation
$blah = Request::get('blah', Request::POST, Request::TYPE_ALNUM);

Now, given that PHP 5.3 has been released I could've gotten REALLY fancy and allowed the $validation parameter to be a lambda callback (I'm running 5.3 …

ShawnCplus 456 Code Monkey Team Colleague

As was noted before, they are superglobals, you can use them anywhere. However, I suggest that you don't. If you're going to go the OOP route then I would suggest abstracting dealing with GET/POST/COOKIE/SESSION variables to a class that deals with them specifically called Request or something along those lines that can appropriately sanitize/parse/etc.

ShawnCplus 456 Code Monkey Team Colleague

You literally just posted the equivalent of a check-engine light. You have to actually explain your problem preferably with code samples

ShawnCplus 456 Code Monkey Team Colleague

I did actually try a variation on the code, as I realized I was checking the wrong variable it should be checking the radio group, so I altered the code slightly

if ($radio='seasons')
{
include('includes/seasons.php');  /* seasons show */
}

if ($radio='products')
{
include('includes/products.php');
}
   ?>

of course its actually showing BOTH currently, mostly likely because i should be using double equals im guessing

Yes, == is a test, = is an assignment. $var = "string" in a condition will always be true.

ShawnCplus 456 Code Monkey Team Colleague

Well that depends on what you want to test. If you want to test for boolean true you'd say

if ($somevariable)

If you wanted to test if the variable was equal to the string "true" then you'd use your way.

ShawnCplus 456 Code Monkey Team Colleague

Was there a question or were you just showing us the code?

ShawnCplus 456 Code Monkey Team Colleague

Read the FAQ

ShawnCplus 456 Code Monkey Team Colleague

http://php.net/isset
If Google is your friend, the PHP manual is your best friend

ShawnCplus 456 Code Monkey Team Colleague

Use <pre> or <code> tags on your output, that's pretty much it. You can do this when you store it but I would highly recommend you do it on output instead.

ShawnCplus 456 Code Monkey Team Colleague

Firstly, toss an echo at the top of your php file to make sure you're even touching that file. Based on your HTML file you may not, type = "submit" those spaces may or may not be killing the submit button.

ShawnCplus 456 Code Monkey Team Colleague

If all you want to do is grab the entire contents of a file and spit it into a textbox then yes, file_get_contents is probably your best bet. If you need to process it then file() or fopen/fread might be the way to go.

ShawnCplus 456 Code Monkey Team Colleague

Now, now, I can't do your entire assignment for you :P
If you get stuck on anything with php the resource to use is http://www.php.net or just Google "php" followed by your question.
Good luck, I hope you get 10/10

A) You already did his entire assignment for him.
B) $char = substr($word,0,1); is the same as $char = $word[0]; C)

$char = substr($word,0,1);
      if ($char != $lastChar)
      {
          $lastChar = $char;
          $i = 0;
      } else {
          $i++;
      }
      $assoc_array[$char][$i] = $word;

is exactly the same as

$assoc_array[$word[0]][] = $word;

Please stop giving them answers to their homework before they show effort.

ShawnCplus 456 Code Monkey Team Colleague
echo "document.write("Hello Dolly");\n";

Use single quotes

echo "document.write('Hello Dolly');\n";
ShawnCplus 456 Code Monkey Team Colleague

Although that's good advice Shawn and I will take note of that.
The only thing I would disagree with is the unset(). I have noticed in the past when reassigning string to variable in a loop a few million times the server runs out of memory where as if unset is used I have noticed the memory problem does not occur.

If you're using the most recent version then that shouldn't happen. If you are using the most recent version then you might want to submit a bug, those are called memory leaks :)

ShawnCplus 456 Code Monkey Team Colleague

Yeah, did you try perhaps googling it and looking at maybe any of the first 1000 results?

ShawnCplus 456 Code Monkey Team Colleague

Some tips for your code cwarn:

Don't use preg_* functions unless absolutely necessary, if you're comparing a static string use strpos or stripos.

Define reused regular expressions in one place (you use /(.*)[.]([^.\?]+)(\?(.*))?/ three times in the same script, define it once in a variable and use it that way, one point of failure is always better.

If you're going to go for speed at the cost of memory usage get rid of in_array. Build an 1-level index and use isset() so you're performing O(1) operations instead of O(n) the in_array and array_key_exists functions are expensive. Example:

$some_big_array = array(1 => somestring, ..., 10000 => anotherstring);

$strings_index = array('somestring' => 1, ...., 'anotherstring' => 1);

$search = 'somestring';
if (isset($strings_index[$search])) // O(1) operation

if (in_array($search, $some_big_array)) // O(n) operation

STOP USING global Don't use unset() right before an assignment of the same variable, ie.,

$datac = "somestring";unset($datac);$datac = "anotherstring";

The unset becomes wasted time because reassignment is an implicit flush of previous memory

ShawnCplus 456 Code Monkey Team Colleague

Post an example string that is to be split, guessing based on your description will produce bad results

ShawnCplus 456 Code Monkey Team Colleague

remove the "ini " before ImageCreateFromJpeg on line 17

ShawnCplus 456 Code Monkey Team Colleague

Store the result in the session, it's that easy

ShawnCplus 456 Code Monkey Team Colleague

A) AJAX and DHTML aren't languages, they're methodologies.
B) All of those languages can be used for the web
C) Use Wikipedia to look up SOAP, it's an acronym hence the capital letters

ShawnCplus 456 Code Monkey Team Colleague

What the heck are you guys doing? He obviously posted a homework question and he never showed any of his own code in this entire thread, all he said is "thanks for the code" and you just handed him answers.

ShawnCplus 456 Code Monkey Team Colleague

Yeah, in the MySQL manual there are in-depth explanations, go take a peek.

ShawnCplus 456 Code Monkey Team Colleague

Have you tried the AUTOINCREMENT property on the field in the database? Go take a look at the MySQL manual

ShawnCplus 456 Code Monkey Team Colleague

It's entirely possible that it's just a Mac thing. It's not like you're going to be running production code on a Mac so I wouldn't really worry about it. If you are thinking of for some stupid reason using your Mac as your server then end that thought quickly :)

ShawnCplus 456 Code Monkey Team Colleague

Thanks for the solution.

If you have any good sites to refresh my memory of this stuff let me know.

Thankyou.

http://http://www.regular-expressions.info/ is probably the most in depth. http://gskinner.com/RegExr is my favorite regex tool

ShawnCplus 456 Code Monkey Team Colleague

Evidently you're not hearing me. Click that link I posted, that's what it does, that's what it was made for, that's what you need. Read it.

ShawnCplus 456 Code Monkey Team Colleague

can you make a example, what I have is a text box that turns in to a variable, then the variable is saved in mysql DB,

it would realy help if you make an example. please...

Yeah, how about you read the link I posted. The PHP manual gives examples for almost every single function built into the language.

ShawnCplus 456 Code Monkey Team Colleague

If you want everything accept for letters and numbers you can use

$pattern = '/[^a-z0-9]/i';

If you are specific about \/:"?<*>| then it's this

$pattern = '#[\/:"\?<\*>|]#';
OmniX commented: Thanks for the solution. +3
ShawnCplus 456 Code Monkey Team Colleague

This is a javascript issue, please post your problem in the appropriate forum.

ShawnCplus 456 Code Monkey Team Colleague

If you're on Windows and you're not willing to move to Linux then you can get WAMP or XAMPP. And I'll tell you right now: lose Netbeans. If you have to use such a bloated IDE use Zend IDE or Eclipse. Netbeans has no place touching PHP in my opinion.

ShawnCplus 456 Code Monkey Team Colleague

I don't believe so but it is possible that CLI and Apache PHP are using separate ini files. Type php --ini to see the ini files it is using.

ShawnCplus 456 Code Monkey Team Colleague

Compare the php.ini's on your Mac and on your Ubuntu machine to see what the difference are. From your unintentionally vague description it's hard to tell what's going on exactly so the ini files are the best place to look.

ShawnCplus 456 Code Monkey Team Colleague

PHP is server-side. It never interacts with the client directly, there is no way it can open any dialog, that's up to Javascript and HTML.

ShawnCplus 456 Code Monkey Team Colleague

nl2br. Please search before posting

ShawnCplus 456 Code Monkey Team Colleague

That's not an error, it's a warning. And C++ std::string::length() returns an unsigned int. You're using an int for your counter in your loop so the comparison j < item.length() is comparing a signed int (default int) to an unsigned int

ShawnCplus 456 Code Monkey Team Colleague

Read the documentation for mysql_connect again. It's mysql_connect('host', 'user', 'password') . You have mysql_connect('host', 'user@host', 'password')

ShawnCplus 456 Code Monkey Team Colleague

Read the FAQ.

ShawnCplus 456 Code Monkey Team Colleague
<?php echo nl2br($whatever) ?>
<?php echo nl2br(substr($whatever)) ?>
ShawnCplus 456 Code Monkey Team Colleague

There's a lot, go read the manual. http://php.net

ShawnCplus 456 Code Monkey Team Colleague

is this a real post or are you trolling? I can't tell