Javascript-php extracts the content in the middle of the string

Source: Internet
Author: User
Who can help me find a better way to use php to extract the content between urscsi and & amp; saU in the following string {code ...} who can help me find a better way to use php to extract the content between urscsi = and & sa = U in the following string?

urlq=https://zh.wikipedia.org/zh/test&sa=U&ved=0ahUKEwjZyO_jtvTKAhXFGh4KHVPkA70QFggeMAE&usg=AFQjCNET0LD_wKKA7nfCkcC44Oii6I13nQ

Reply content:

Who can help me find a better way to use php to extract the content between urscsi = and & sa = U in the following string?

urlq=https://zh.wikipedia.org/zh/test&sa=U&ved=0ahUKEwjZyO_jtvTKAhXFGh4KHVPkA70QFggeMAE&usg=AFQjCNET0LD_wKKA7nfCkcC44Oii6I13nQ

Regular Expression

$str = 'urlq=https://zh.wikipedia.org/zh/test&sa=U&ved=0ahUKEwjZyO_jtvTKAhXFGh4KHVPkA70QFggeMAE&usg=AFQjCNET0LD_wKKA7nfCkcC44Oii6I13nQ';preg_match("/urlq=(.*?)&sa/", $str, $a);$b = $a[1];echo $b;

Split

$str = 'urlq=https://zh.wikipedia.org/zh/test&sa=U&ved=0ahUKEwjZyO_jtvTKAhXFGh4KHVPkA70QFggeMAE&usg=AFQjCNET0LD_wKKA7nfCkcC44Oii6I13nQ';$str1 = explode('urlq=', $str);$str2 = explode('&sa', $str1[1]);$b = $str2[0];echo $b;

Check whether the parse_url function works.

Give you a UDF

// $ Kw1 is the string to be intercepted // $ mark1 start character // $ mark2 is the ending character // returns an intercepted string // function getNeedBetween ($ kw1, $ mark1, $ mark2) {$ kw = $ kw1; $ kw = '000000 '. $ kw. '20140901'; $ st = stripos ($ kw, $ mark1); $ ed = stripos ($ kw, $ mark2 ); if ($ st = false | $ ed = false) | $ st >=$ ed) return 0; $ kw = substr ($ kw, ($ st + 1), ($ ed-$ ST-1); return $ kw ;}

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.