在php中使用正则表达式拆分字符串
发布时间:2020-12-13 22:05:24 所属栏目:PHP教程 来源:网络整理
导读:我是php的初学者,我有这样的字符串: $test = http://localhost/biochem/wp-content/uploads//godzilla-article2.jpghttp://localhost/biochem/wp-content/uploads/life-goes-on-wpcf_300x111.jpg 我想将字符串拆分为这样的数组: Array([0] = http://localh
我是php的初学者,我有这样的字符串:
$test = http://localhost/biochem/wp-content/uploads//godzilla-article2.jpghttp://localhost/biochem/wp-content/uploads/life-goes-on-wpcf_300x111.jpg 我想将字符串拆分为这样的数组: Array( [0] => http://localhost/biochem/wp-content/uploads//godzilla-article2.jpg [1] => http://localhost/biochem/wp-content/uploads/life-goes-on-wpcf_300x111.jpg ) 我该怎么办? 解决方法$test = 'http://localhost/biochem/wp-content/uploads//godzilla-article2.jpghttp://localhost/biochem/wp-content/uploads/life-goes-on-wpcf_300x111.jpg'; $testurls = explode('http://',$test); foreach ($testurls as $testurl) { if (strlen($testurl)) // because the first item in the array is an empty string $urls[] = 'http://'. $testurl; } print_r($urls); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |