SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jun 2005
    Location
    Oslo, Norway
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cannot redeclare stripos() - PHP4 to PHP5 problem

    My host upgraded PHP from version 4.4 to 5.2 and a custom script I am useing stopped working and I got this error messsage:

    Code:
    Fatal error: Cannot redeclare stripos() in /home/xxx/public_html/library/functions.php on line 6
    The code that is reffering too is:

    PHP Code:
    <?php
    function stripos($haystack$needle)
    {
      
    $offset=0;
      return 
    strpos(strtoupper($haystack), strtoupper($needle), $offset);
    }
    function 
    geturl($rawurl// Process the raw URL
    {
            
    $processed_url ="/".$rawurl;
            
    $lastchar substr($processed_url, -11);
            if (
    $lastchar == '/'){}
            else
                {
                    
    $processed_url $processed_url."/";
                }
            return 
    $processed_url;
    }
    Is there a way I can fix this?
    Neteffects offer Search Marketing Services to European Clients.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Change the name.

    Or see if http://php.net/stripos does what you want.

    Which it does from what I see.

    --------------------
    For backwards compatibility with PHP4 I would change the above to:
    Code php:
    if (!function_exists('stripos')) {
        function stripos() {
            ...
        }
    }
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    Jun 2005
    Location
    Oslo, Norway
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for responding, logic_earth.

    I am not a PHP programmer myself, so I cant really fix it unless I am told what code to replace.

    What name should I change?
    Neteffects offer Search Marketing Services to European Clients.

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Change:
    Code PHP:
    function stripos($haystack, $needle) {
        $offset=0;
        return strpos(strtoupper($haystack), strtoupper($needle), $offset);
    }

    To:
    Code PHP:
    if (!function_exists('stripos')) {
        function stripos($haystack, $needle, $offset = 0) {
            return strpos(strtoupper($haystack), strtoupper($needle), $offset);
        }
    }
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    The reason you are getting this error is because stripos is a built in function in PHP5 but it was not in PHP4.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  6. #6
    SitePoint Member
    Join Date
    Jun 2005
    Location
    Oslo, Norway
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is just fantastic!

    That worked great...! I am sooo happy you helped me getting that site working again! Thanks a lot for taking the time to help me :-)
    Neteffects offer Search Marketing Services to European Clients.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •