Rumah > pembangunan bahagian belakang > tutorial php > 求大神一个简单的正则去除

求大神一个简单的正则去除

WBOY
Lepaskan: 2016-06-23 14:02:15
asal
1050 orang telah melayarinya

    Array        (            [0] => ts3.mm.bing.net/th?id=H.4877189679415314&pid=1.7&w=140&h=153&c=7&rs=1" style="height:153px;"/>            [1] => ts4.mm.bing.net/th?id=H.4541061266538791&pid=1.7&w=159&h=153&c=7&rs=1" style="height:153px;"/>            [2] => ts3.mm.bing.net/th?id=H.5012914882808678&pid=1.7&w=124&h=153&c=7&rs=1" style="height:153px;"/>            [3] => ts2.mm.bing.net/th?id=H.4755508963443465&pid=1.7&w=187&h=153&c=7&rs=1" style="height:153px;"/>            [4] => ts1.mm.bing.net/th?id=H.5001765194041784&pid=1.7&w=144&h=146&c=7&rs=1" style="height:146px;"/>)
Salin selepas log masuk


求大神怎么去除这个数组&之前的所有数据
例如ts3.mm.bing.net/th?id=H.4877189679415314&pid=1.7&w=140&h=153&c=7&rs=1" style="height:153px;"/>
变成ts3.mm.bing.net/th?id=H.4877189679415314


回复讨论(解决方案)

明明是“后”偏要说是前

$ar = array('ts3.mm.bing.net/th?id=H.4877189679415314&pid=1.7&w=140&h=153&c=7&rs=1" style="height:153px;"/>','ts4.mm.bing.net/th?id=H.4541061266538791&pid=1.7&w=159&h=153&c=7&rs=1" style="height:153px;"/>','ts3.mm.bing.net/th?id=H.5012914882808678&pid=1.7&w=124&h=153&c=7&rs=1" style="height:153px;"/>','ts2.mm.bing.net/th?id=H.4755508963443465&pid=1.7&w=187&h=153&c=7&rs=1" style="height:153px;"/>','ts1.mm.bing.net/th?id=H.5001765194041784&pid=1.7&w=144&h=146&c=7&rs=1" style="height:146px;"/>',);$p = new ArrayIterator($ar); $i = new RegexIterator($p, '/&.*$/', RegexIterator::REPLACE); $i->replacement = '';        print_r(iterator_to_array($i)); 
Salin selepas log masuk
Array
(
[0] => ts3.mm.bing.net/th?id=H.4877189679415314
[1] => ts4.mm.bing.net/th?id=H.4541061266538791
[2] => ts3.mm.bing.net/th?id=H.5012914882808678
[3] => ts2.mm.bing.net/th?id=H.4755508963443465
[4] => ts1.mm.bing.net/th?id=H.5001765194041784
)

不行啊 这个类 需要开启吗

返回一个空数组

RegexIterator
PHP 5 >= 5.2.0

不用迭代器的写法

$ar = array('ts3.mm.bing.net/th?id=H.4877189679415314&pid=1.7&w=140&h=153&c=7&rs=1" style="height:153px;"/>','ts4.mm.bing.net/th?id=H.4541061266538791&pid=1.7&w=159&h=153&c=7&rs=1" style="height:153px;"/>','ts3.mm.bing.net/th?id=H.5012914882808678&pid=1.7&w=124&h=153&c=7&rs=1" style="height:153px;"/>','ts2.mm.bing.net/th?id=H.4755508963443465&pid=1.7&w=187&h=153&c=7&rs=1" style="height:153px;"/>','ts1.mm.bing.net/th?id=H.5001765194041784&pid=1.7&w=144&h=146&c=7&rs=1" style="height:146px;"/>',);foreach($ar as &$r)  $r = preg_replace('/&.+$/', '', $r);print_r($ar);
Salin selepas log masuk
Array
(
    [0] => ts3.mm.bing.net/th?id=H.4877189679415314
    [1] => ts4.mm.bing.net/th?id=H.4541061266538791
    [2] => ts3.mm.bing.net/th?id=H.5012914882808678
    [3] => ts2.mm.bing.net/th?id=H.4755508963443465
    [4] => ts1.mm.bing.net/th?id=H.5001765194041784
)

楼上正解

明明是“后”偏要说是前PHP code?123456789101112$ar = array('ts3.mm.bing.net/th?id=H.4877189679415314&pid=1.7&w=140&h=153&c=7&rs=1" style="height:153px;"/>','ts4.mm.bing.net/th?id=……
此方法拿来收藏一下

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan