user5405873 user5405873 - 3 months ago 10
PHP Question

after .com slash is missing in the url how can i append it

here is my array with all urls.
there are some urls such as http://www.floretmedia.comcontact-us.php where / is missing after .com how can i append /.

Array
(
[0] => http://www.pepagora.com/product/contactors
[1] => http://www.pepagora.com/contact
[2] => http://www.pepagora.com/contact/advertiseWithUs
[3] => http://www.floretmedia.comcontact-us.php // after .com / is missing
[4] => http://floretmedia.com/contact-us.php
[5] => http://www.coviam.comcontact-us.php // after .com / is missing
[6] => http://www.nexevo.in/Contact-Us.html
[7] => http://www.thidiff.com/contact-us
)


iam able to append/prepend http:// with this code

if (!preg_match("~^(?:f|ht)tps?://~i", $page)) {
$page = "http://" . $page;
}


but dont know for / after .com please help me thanks in advance

Answer

u can use this code

$result = array();
foreach ($array as $key => $value) {
    $split = split('.com', $value);
    if(isset($split[1]) && $split[1][0]!='/'){
        $url = $split[0].'.com/'.$split[1];
        $result[] = $url;
    } else {
        $result[] = $value;
    }
}
var_dump($result);

the result variable will give you result with all missing .com/