第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 特定字符之前和之后的子字符串,直到空格、逗號...?

PHP 特定字符之前和之后的子字符串,直到空格、逗號...?

PHP
德瑪西亞99 2023-12-15 16:15:17
我正在嘗試抓取一封電子郵件。假設(shè)我有一個很長的字符串:$str = "this is the email query@stackoverflow.com which you might want to scrape";$needle_1 = "@";$needle_2 = array("[ ]","[,]","["]");我想提取電子郵件。我認(rèn)為使用@是解決方案。 所以基本上,我需要獲取@之前和之后的所有字符,直到空格、逗號或"。目前最好的試用是:$string = 'this is the email query@stackoverflow.com which you might want to scrape';$template = "/[\w]+[@][\w]+[.][\w]+/";preg_match_all($template, $string, $matches);var_dump($matches);我怎樣才能做到這一點?
查看完整描述

2 回答

?
千巷貓影

TA貢獻(xiàn)1829條經(jīng)驗 獲得超7個贊

我認(rèn)為它看起來更好


  $string = 'this is the email query@stackoverflow.com which you might want to scrap';

  $template = "/[\w]+[@][\w]+[.][\w]+/";

  preg_match_all($template, $string, $matches);

  var_dump($matches);


查看完整回答
反對 回復(fù) 2023-12-15
?
鴻蒙傳說

TA貢獻(xiàn)1865條經(jīng)驗 獲得超7個贊

您應(yīng)該為此創(chuàng)建一個正則表達(dá)式:


<?php 

    $str = "this is the email query@stackoverflow.com which you might want to scrap";

    $pattern = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';

    preg_match_all($pattern, $str, $matches);

    var_dump($matches[0]);

?>


查看完整回答
反對 回復(fù) 2023-12-15
  • 2 回答
  • 0 關(guān)注
  • 236 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號