取子串的正则表达式
有如下字符串:
"
用正则表达式如何取出"name1"和"name2"呢?谢谢
------解决方案--------------------
<?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>
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 $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>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号