取子串的正则表达式,该怎么处理
Jun 13, 2016 am 10:00 AM
gt
lt
quot
str
取子串的正则表达式
有如下字符串:
"
用正则表达式如何取出"name1"和"name2"呢?谢谢
------解决方案--------------------
- PHP code
<?php $str = "<str1>name1<str2>name2</str2>";$patten = "/<str>([^/isU";preg_match_all($patten,$str,$matches);print_r($matches[1]);<br><font color="#e78608">------解决方案--------------------</font><br><dl class="code">PHP code<pre class="brush:php;toolbar:false">$str = "<str1>name1</str1><str2>name2</str2>";preg_match_all('/>([^ name1 [1] => name2 ) */<br><font color="#e78608">------解决方案--------------------</font><br>
登入後複製
- PHP code
preg_match_all("/>[^<font color="#e78608">------解决方案--------------------</font><br>$str = "<str1>name1</str1><str2>name2</str2>";<br>preg_match_all('/>([^print_r($matches[1]);<br>/**<br>输出结果:<br>Array ( [0] => name1 [1] => name2 ) <br>*/<br><br><font color="#e78608">------解决方案--------------------</font><br>
登入後複製
- PHP code
<?php $str="<str1>name1<str2>name2</str2>"; $preg="#<str1>(.*)</str1><str2>(.*)</str2>#"; preg_match($preg,$str,$arr); echo $arr[1]; echo $arr[2];?><br><font color="#e78608">------解决方案--------------------</font><br><?php <br /> $str="<str1>name1</str1><str2>name2</str2>";<br> preg_match_all("/([^]*)/",$str,$matches);<br> echo $matches[1][0];<br> echo $matches[1][1];<br>?><br><br><font color="#e78608">------解决方案--------------------</font><br>"/>(.*?)<font color="#e78608">------解决方案--------------------</font><br>
登入後複製
------解决方案--------------------
$str="
preg_match_all("/([^]*)/",$str,$matches);
echo $matches[1][0];
echo $matches[1][1];
?>
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保護它?
3 週前
By DDD

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保護它?
3 週前
By DDD

熱門文章標籤

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Microsoft正在推出Windows 11 23H2版本到有Copilot的發布預覽頻道
