Jump to content

Koobi

Staff Alumni
  • Posts

    419
  • Joined

  • Last visited

    Never

Posts posted by Koobi

  1. try working backwards then.

     

    check the results of $z like this:

    <?php
        echo '<pre>' . print_r($z, true) . '</pre>';
    ?>
    

     

    and if $z does contain what you expect, then go backwards and do the same for $page, etc until you see something that we might find useful to solve this problem and post it here.

     

     

     

     

     

    also, you had this earlier:

    <?php
    $$z['Short'] = $z['Long'];
    ?>
    

     

     

    but now you have this:

    <?php
    $z['Short'] = $z['Long'];
    ?>
    

     

    just pointing it out because your code would have failed earlier anyway.

  2. usually, an SQL string manipulation would work faster than a PHP string manipulation so you might want to give roopurts method out. but since it's a CONCAT function, you might want to take a benchmark and compare the two results.

  3. link=topic=138703.msg588249#msg588249 date=1178051805]

    ok... how about using $_SESSION instead?

     

    a session is...a session :)

     

    the moment you end that session by either leaving the site or a page (depending on how you have set it up), that session data is lost forever...unless you store it as a cookie or in the db.

     

    this is not PHP's fault, it's because HTTP is a stateless protocol. we wouldn't even need sessions for most things if HTTP wasn't stateless.

  4. i'm sorry, i just realized i've made a mistake. since the code i posted is adding a decimal number, you will get WLK2

     

     

    what you could do is use str_pad()

    <?php
        $old_code = 'WLK0001';
        $added_num = substr($old_code, -4) + 1;
        $new_code = substr($old_code, 0, 3) . str_pad($added_num, 4, '0', STR_PAD_LEFT);
    
        echo $new_code;
    ?>
    

     

     

    but this is also not tested so try it out and let me know.

  5. are you certain that the last 4 digits will always be numeric?

     

    if so, you can try this:

    <?php
        $old_code = 'WLK0001';
        $new_code = substr($old_code, 0, 3) . (substr($old_code, -4) + 1);
    
        echo $new_code;
    ?>
    

     

     

    it might be better for you to throw in a is_numeric() or, better yet, ctype_digit() function in there too.

  6. yeah i agree on the FTP username issue.

     

    but other than that, i think they are pretty good. I've used them a couple of times via some clients. i hear that they got the best domain registration award last year.

  7. cookies would work but they can be spoofed and as roopurt18 mentions, you can turn cookies off as well.

     

    if your users log in, your best bet would be to have a little column in this users table which contains the number of visits he's had to this page. increase the count in this table row for that customer on each visit and keep track via that table.

     

     

    if your users don't login, then i guess cookies would work best for you. but i think someone else might be able to answer this part better, hopefully as i'm not 100% sure of the best method for such a thing when the user is not logged in.

  8. as Wildbug said, error messages would be very useful. that is the reason they exist, so that we can use them to debug the problem.

     

     

     

    one thing that could be causing the problem is that your upload limit maybe smaller than the size of the file you are trying to upload. but i'll wait for your reply with the exact errors before i elaborate.

  9. i believe include and require (and their variants) use the filesystem to include the file so when you pass _GET variables, it will probably search the file system for a file with that name,

     

     

    your code probably is looking for a file named 'comments.php?id=1' but only 'comments.php' exists.

     

     

    you'd typically use include or require if you want to include the raw PHP code to be processed on the page.

     

    you could try this:

    <?php
    $_GET['id'] = 1;
    include ("../iandotcom/comments/comments.php");		
    ?>
    

     

     

    that might work for you if your code looks for a _GET['id'] to process whatever it is you are processing.

  10. strip_tags() will strip out anything within HTML tags (unless you use the optional parameter to define a set of tags you want to allow) but you can also use str_replace() to do what you need most efficiently.

  11. i make this mistake a lot too which is probably why i caught this out :)

     

    <?php
    if($y=$z) { echo $z['Long'];}
    ?>
    

     

     

    in the above, you are trying to assign $z to $yz and an assignation will always work...unless you are trying to assign a value to a previously defined constant and therefore, your if condition will ALWAYS be true.

     

    you have to use either '==' or '===' depending on your needs.

     

     

    what happens in between the if conditions brackets is that the code in there is evaluated (think var_dump()) and the if condition itself receives the boolean result of what is in the brackets.

    so, you assigning $z to $y will always return a true to IF since that is a perfectly legal thing to do in PHP.

     

     

     

     

     

    btw, you can correct your code by making it like this:

    <?php
    if($y == $z) { echo $z['Long'];}
    ?>
    

  12. i'm not sure about windows, but on Linux, you can have as many php.ini files as you want and place them in a directory and your phpinfo() would show that directory as the location of php.ini

     

    for example, one of our clients servers at work has the following path to php.ini:

    /etc/php.d/
    

     

    and the folder '/etc/php.d/' contains many .ini files pertaining to a specific extension of PHP.

     

     

     

    the most effective way to determine if your PHP settings are working as they should would be to make a change in your current php.ini and restart the web server and have a look at phpinfo() again to determine if the changes you made are reflected in it.

  13. Any Python coders here can appreciate the utility of an interactive shell. A tool that I use regularly is PHP Interactive, a web tool that tries to mimic that functionality. It's especially nice when working w/ php freaks because I can quickly test a piece of code, w/o having to open an editor, save a file, test it in a web page.

     

    http://www.hping.org/phpinteractive/

     

    i downloaded the tool ages ago via this thread but i only tried it out recently.

     

    great tool. makes life so much easier!

  14. well it looks like Zend Core 2.0 was a buggy release.

     

    i contacted their tech support because it kept giving me errors that i know didn't exist on the system because i set it up myself and the tech guy logged in via SSH and after about two days told me that there seems to be a problem with Zend Core 2.0 that other customers had been experiencing as well and that they are releasing Zend Core 2.1 today (apr 22, 2007) so i'll give that a go tomorrow and hope for the best!

  15. what do you mean by 'Linux project'? is it to do with the OS only and not necessarily PHP?

     

    why don't you use the linux diff command? if you have to use PHP, then you can still use exec() wifh diff and grab the output and format it to display what you need.

  16. I did the test exam three times, copy-pasted and looked into questions I had to guess. I had a quick read through the Certification Guide, but there's not much really new in there if you're a relatively experienced php5 coder.

     

    The last time I did the test exam I scored 'excellent' on all subjects. But I think that was mostly because I had been taking notes, and the questions in the test exam are very much related I feel. The real exam may cover the same general subjects, the subtopics where mostly very different. I didn't think the real exam was easier than the test exam, as php|architect claims. But that could have been my nerves and the (annoyingly) loud buzzing of monitors on the background.

     

    Anyway, the bottom line is: if you keep a cool head it shouldn't prove that hard - more experienced php5 coders won't really need to study. Do the test exam to get where you stand, but more than twice is pretty useless.

     

    I'm not allowed to talk about the content of the test though, they had me sign a non-disclosure..  :(

     

    Sorry if all of this doesn't really help...

     

    i agree. i've done the practice test for PHP 4 and it's not hard...but some of the questions were...unexpected and unnecessary. anyway i thought i'd stay till i learnt PHP 5 since that was coming out at the time. i've finally found some time to learn the new things about php 5 over the last few weeks.

  17. You don't catch multiple errors.  The purpose of try/catch is to stop the try statement as soon as the first exception is encountered, and then run the catch block of code.  It is intended to work the way it works, and I do not believe it has any method of capturing multiple exceptions.

     

    thanks Glyde. i thought that exceptions was meant for this sort of thing. what is it really meant for anyway?

     

     

     

    perhaps

     

    <?php 
    class My_Validation
    {
        public $excepts;
        
        function __construct () {
            $this->excepts = array();
        }
        
        public function valid_numeric ($val) {
            if (ctype_digit($val)) {
                return TRUE;
            } else {
                $this->excepts[] =  new Exception('Not a valid digit', 0);
                return FALSE;
            }
        }
    
    
        public function valid_alphanumeric ($val) {
            if (ctype_alnum($val)) {
                return TRUE;
            } else {
                $this->excepts[] = new Exception('Not a valid alphanumeric', 0);
                return FALSE;
            }
        }
    
        function __destruct () {
        }
    
    }
    
    
    $validation = new My_Validation;
    
    try {
    
        $validation->valid_numeric('4f');
        $validation->valid_alphanumeric('5.r');
        
        if ($validation->excepts) {
            foreach ($validation->excepts as $e)
                echo  $e->getmessage().'<br>';
        }
        
    } catch (Exception $error) {
        echo '<pre>' . print_r($error, true) . '</pre>';
    }
    
    
    ?>
    

     

    that would work fine, thanks.

     

     

     

     

    but do you think it's best practice to throw the exception inside my validation class or within the procedural code, like this:

    
    
    class My_Validation
    {
        function __construct () {
        }
        
        public function valid_numeric ($val) {
            if (ctype_digit($val)) {
                return TRUE;
            } else {
                return FALSE;
            }
        }
    
    
        public function valid_alphanumeric ($val) {
            if (ctype_alnum($val)) {
                return TRUE;
            } else {
                return FALSE;
            }
        }
    
        function __destruct () {
        }
    
    }
    
    
    $validation = new My_Validation;
    
    try {
    
        if ($validation->valid_numeric('4f') === FALSE) {
            throw new Exception('Not a valid digit', SOME_ERROR_CODE_CONSTANT);
        }
    
        if ($validation->valid_alphanumeric('5.r') === FALSE) {
            throw new Exception('Not a valid alphanumeric', SOME_OTHER_ERROR_CODE_CONSTANT);
        }
        
    } catch (Exception $error) {
        echo '<pre>' . print_r($error, true) . '</pre>';
    }
    
    
    

  18. 7zip has an amazing compression ratio. almost 50% better than .zip, i think.

     

    PHP's zip library supports the .zip compression format and zlib in PHP supports the .gz compression format...but as gluck suggested, you might have to use PHP's exec() to run a system call to handle the 7zip format. make sure exec() hasn't been disabled in php.ini and note that if your PHP is on safe_mode, you might have to overcome some issues. Just look up 'safe_mode in php.ini' in the manual.

  19. just as it's been mentioned here, you can totally customize Linux which you can't do in Windows because you don't have access to the Windows source code whereas in Linux, you can even alter the OS by recompiling the kernel.

     

    in linux, you can add your own Desktop environment (GNOME, KDE, XFCE, Orchestra, etc) but you can't do this in Windows...not easily anyway.

     

    total control, even upto the point where you can dictate the way your hardware interacts with your software...although this is not a good thing all the time, i learnt that :/

     

    you know what, there are too many things to mention. this might turn out better if you asked us if task X can be done in linux, chances are, it can be done in Linux :)

  20. here's an example:

     

    <?php
    
    
    class My_Validation
    {
        function __construct () {
        }
        
        public function valid_numeric ($val) {
            if (ctype_digit($val)) {
                return TRUE;
            } else {
                throw new Exception('Not a valid digit', SOME_ERROR_CODE_CONSTANT);
                return FALSE;
            }
        }
    
    
        public function valid_alphanumeric ($val) {
            if (ctype_alnum($val)) {
                return TRUE;
            } else {
                throw new Exception('Not a valid alphanumeric', SOME_OTHER_ERROR_CODE_CONSTANT);
                return FALSE;
            }
        }
    
        function __destruct () {
        }
    
    }
    
    
    $validation = new My_Validation;
    
    try {
    
        $validation->valid_numeric('4f');
        $validation->valid_alphanumeric('5.r');
        
    } catch (Exception $error) {
        echo '<pre>' . print_r($error, true) . '</pre>';
    }
    
    
    ?>
    

     

     

    The problem is, $error only contains the first exception thrown by My_Validation::valid_numeric.

    I want both throws to be caught there so that I can display them.

×
×
  • 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.