There is a list urls like
"http://books.rediff.com/categories/travel/general/2288"

I wish to find out whether they start from "http:/" or are relative urls starting from "/", if true store them in an array !

...
if (strpos($html->href, 'http://') <= 0) {
        array_push($urlarray, $link->href);
}
...

This does not work ....
How should I do it ??

Please help!

Member Avatar
diafol

Use parse_url()

str_pos() returns boolean (TRUE or FALSE). Should be

if (strpos($html->href, 'http://') !== FALSE) {
    //there is http in the url, then do this statement
    // your code
}

Or use @diafol method.

str_pos() returns boolean (TRUE or FALSE)

Incorrect. It returns the index (starting from 0) at which the needle was found in the haystack.

If the needle wasn't found, it returns false. Hence why you need to test for absolutely equal to false, rather than equal to false to avoid false positives if 0 is returned.

commented: Thanks for correcting. +8

Oop ! Sound likes suck! But, you're right. :) Thanks for alert @blocblue.

if (strpos($link->href, 'http://') === 0) {
        array_push($urlarray, $link->href);
    }

I have corrected that ... "===" was to be used rather than "==" or "<=" etc.