I've just run into this error, which is I believe caused by some php5 requirement.

        $site = substr($p, 0, $pos); //http://www.google.com
        $site = str_replace('http://', '', $site, 1);

What I'm trying to do is very simple: slowly dissect a url step by step.

I tried to put a $foo = $site after the first line and use $foo instead of $site on line 2--something I read while googling-- but it did nothing to fix the problem (as expected).

Could someone shed light on the issue?

    The 4th parameter to str_replace() must be a variable. Its purpose is to store the count of how many replacements are done by the function. It is an optional parameter, so if you don't need to do anything with it, you can just leave it out, but "1" is not a variable and thus is invalid.

      Whoops!

      Just to confirm--I added a number as the last value assuming that it was taken to be the number of instances to change.

      This confusion was caused by php.net which states an optional input value named $count. $count is not an int as I originally thought, but a var which will hold the number of terms changed...

        Oni;10899279 wrote:

        What I'm trying to do is very simple: slowly dissect a url step by step.

        Could someone shed light on the issue?

        Could you not simply use parse_url() ?

        Example:

        $str = 'http://www.google.com';
        $arr = parse_url($str);
        echo '<pre>'.print_r($arr, true);
        

        Output:

        Array
        (
            [scheme] => http
            [host] => www.google.com
        )
        

        Granted, your initial string has // infront of the http... You could simply strip out any such characters before plugging into the parse_url function..

        $str = '//http://www.google.com';
        $str = preg_replace('#^[/]+#', '', $str); // you can add other non alpha characters inside this character list if need to be... hence why it is a character class
        $arr = parse_url($str);
        echo '<pre>'.print_r($arr, true);
        

          Why yes I could have, If id had known of such a thing! :rolleyes:

            Write a Reply...