㈠ 请问怎样用php 正则表达式取设置宽和高的[img][/img]标签里面的图片地址
用php给你运行了一个
$txt='[img=442,296]图片地址1[/img]
[img=300,188]图片地址2[/img]
[img=120,206]图片地址3[/img]';
$re='/[img=(d+,d+)](S+?)[/img]/';//这里修改下,加上一个?防止以单行文本导致的定界符不准问题
$arr=[];
preg_match_all($re,$txt,$arr);
var_mp($arr);
运行结果如下
phptest.php
array(3){
[0]=>
array(3){
[0]=>
string(32)"[img=442,296]图片地址1[/img]"
[1]=>
string(32)"[img=300,188]图片地址2[/img]"
[2]=>
string(32)"[img=120,206]图片地址3[/img]"
}
[1]=>
array(3){
[0]=>
string(7)"442,296"
[1]=>
string(7)"300,188"
[2]=>
string(7)"120,206"
}
[2]=>
array(3){
[0]=>
string(13)"图片地址1"
[1]=>
string(13)"图片地址2"
[2]=>
string(13)"图片地址3"
}
}
//增加一个矩阵转换
$txt='[img=442,296]图片地址1[/img][img=300,188]图片地址2[/img][img=120,206]图片地址3[/img][img=120,206]wwww[/img]';
$re='/[img=(d+,d+)](S+?)[/img]/';
var_mp(preg_match_all_to_array($re,$txt));
functionpreg_match_all_to_array($re,$txt)
{
$arrs=[];
preg_match_all($re,$txt,$arrs);
if($arrs===false)
return$arrs;
//移除到总匹配数据
array_shift($arrs);
$return=[];
//获取矩阵纵长
$arrs_longitudinal=count($arrs);
for($i=0;$i<$arrs_longitudinal;$i++){
//获取单列横长
$arrs_transverse=count($arrs[$i]);
for($j=0;$j<$arrs_transverse;$j++){
$return[$j][$i]=$arrs[$i][$j];
unset($arrs[$i][$j]);
}
unset($arrs[$i]);
}
return$return;
}
㈡ PHP正则表达式 提取图片链接
/\<a[^>]+href=['"]([^'"]+)['"][^\>]+\>[^<]*\<img[^>]+src=['"]([^'"]+)['"][^>]*\>/i
php里面注意引号的转义
㈢ PHP急求如何用一个正则表达式匹配出下图中id的值与title的内容并保存为id=693,title=A AC宝马这样的格式
<?php
$str='[{"id":"123","title":"title","text":"text"},{"id":"1231","title":"title1","text":"text1"}]';
preg_match_all('/"id":"(d+)","title":"(.*?)",/is',$str,$matched,PREG_SET_ORDER);
foreach($matchedas$row){
echo'id='.$row[1].',title='.$row[2].'<br/>';
}
//如果是完整json字符串,直接解析更好
echo"<pre>";
print_r(json_decode($str,true));
echo"</pre>";
exit;
㈣ php 正则表达式怎么把图片URL匹配出来呢
使用preg_match_all函数,即可实现你的要求。代码如下:
$str='<imgdatasrc="http://mm..com/mmbiz/2ItUdTx3iamOFK8QVqofnQ/640?tp=webp"data-s="300,640"data-ratio="0.625"data-w="400"style="box-sizing:border-box!important;width:auto!important;word-wrap:break-word!important;visibility:visible!important;"/>';
$pattern='/<img.*src="(.*?)"/';
preg_match_all($pattern,$str,$matches);
echo$matches[1][0];
//返回:http://mm..com/mmbiz/2ItUdTx3iamOFK8QVqofnQ/640?tp=webp
㈤ php如何使用正则表达式匹配url图片啊
$pregRule = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
正则匹配URL图片
㈥ 请教!php 正则表达式匹配图片问题。
<?php
$str = preg_replace("/height='[0-9]+?'/","width='100%'",$str);
?>
函数例子:http://hi-docs.com/php/preg_replace.html
㈦ php匹配正则表达式
<?php
$content="ad你好asd/dasds*@~as/d,.^asdasda.jpg,11/das,看看ds*~as/d.^asdasda.jpg,1&1/dd,s*~as/d,.^asda.png";
if(preg_match_all("/[^,][wW]+?.(jpg|gif|png)/s",$content,$matches)){
var_mp($matches[0]);
}
?>
㈧ php正则表达式[img=**]
按照你的要求编写的php程序如下(见图,正则匹配结果取第一和第二捕获组的数据)
㈨ 急求 php正则表达式匹配16个数字名字的图片 如 1470311681602444.jpg
路过而已,但是另外一个答案写错了,所以就纠正一下吧。不应该用 [] 应该用 ()
preg_match('#d{16}.(jpg|png|gif|jpeg|bmp)#',$str);
如果要判断字符串是不是完全符合这个规则要加上 ^ 和 $
preg_match('#^d{16}.(jpg|png|gif|jpeg|bmp)$#',$str);
㈩ PHP正则表达式为什么死活无法匹配图片,一到引号[\"]或者<,还有[.]就匹配不了,为什么,急求
在正则表达式中,若要匹配以下单个字符,都需要用反斜杠("\")进行转义:"\"、"?"、"*"、"^"、"$"、"+"、"("、")"、"|"、"{"、"["