A simple regular expression removal

Source: Internet
Author: User
A simple regular expression removal
    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;"/>)


How can I remove this array and all the previous data?
For example, ts3.mm.bing.net/th? Id = H.4877189679415314 & pid = 1.7 & w = 140 & h = 153 & c = 7 & rs = 1 "style =" height: 153px; "/>
To ts3.mm.bing.net/th? Id = H.4877189679415314


Reply to discussion (solution)

Obviously "post" is to say "before"

$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)); 
Array
(
[0] => ts3.mm.bing.net/th? Id = H.4877189679415314
[1] => ts4.mm.bing.net/th? Id = h.4543161266538791
[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.5001765194042684
)

No. does this class need to be enabled?

Returns an empty array.

RegexIterator
PHP 5> = 5.2.0

Writing without an iterator

$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);
Array
(
[0] => ts3.mm.bing.net/th? Id = H.4877189679415314
[1] => ts4.mm.bing.net/th? Id = h.4543161266538791
[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.5001765194042684
)

Upstairs positive solution

Obviously "post" is the former 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 = ......
Add this method to favorites

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.