时间戳转换工具

php提取字符串小括号里面的内容

1.使用preg_replace()函数提取第一个小括号()中的内容:

<?php
$str = '珠穆朗玛峰海拔为(8844.43)米.';
echo preg_replace("#^.*?\((.*?)\).*?$#us", "$1", $str);
//输出: 8844.43


2.使用preg_match()函数提取第一个小括号()中的内容:

<?php
$str = '爱E族(http://aiezu.com).';
preg_match("#\((.+?)\)#us", $str, $match);
print_r($match);

输出:
Array
(
[0] => (http://aiezu.com)
[1] => http://aiezu.com
)


3.使用preg_match_all()函数提取所有小括号()中的内容:

<?php
$str = '网站(爱E族),网址(aiezu.com).';
preg_match_all("#\((.*?)\)#us", $str, $match);
print_r($match);

输出:

Array
(
[0] => Array
(
[0] => (爱E族)
[1] => (aiezu.com)
)
[1] => Array
(
[0] => 爱E族
[1] => aiezu.com
)
)


联系我们 - 首页 - 关于我们
Copyright © 2017-2022 iteam. All Rights Reserved. Current version is 2.50.0.
粤ICP备17021424号
VV:34926 UV:113662 PV:388047