这是我所有网址的数组。有一些网址,例如http://www.floretmedia.comcontact-us.php,其中.com后缺少/,我如何附加/。
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可以使用此代码附加/添加http://
if (!preg_match("~^(?:f|ht)tps?://~i", $page)) {
$page = "http://" . $page;
}
但不知道/.com之后,请先帮助我,谢谢
您可以使用此代码
$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);
结果变量将为您提供所有缺少的.com /的结果
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句