基本上我收到了这个:
<iframe width='425' height='350' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://maps.google.com.br/maps?f=q&source=s_q&hl=pt-BR&geocode=&q=R.+Alm%C3%A9ria,+242+-+Penha,+S%C3%A3o+Paulo+-+S%C3%A3o+Paulo&aq=0&oq=Rua++Almeria&sll=-14.239424,-53.186502&sspn=79.602428,135.263672&t=h&ie=UTF8&hq=&hnear=R.+Alm%C3%A9ria,+242+-+Penha,+S%C3%A3o+Paulo,+03654-000&z=14&ll=-23.524401,-46.518859&output=embed'></iframe>
我需要做的是将width =''引号或双引号内的任何值替换为另一个值。
我对正则表达式并不擅长,试图通过这种方法学习似乎很复杂。
有什么想法吗?
感谢。
答案 0 :(得分:0)
我不久前回答了类似的问题 - &gt; How to replace width and height an iframe html tag using php?
更好地使用str_replace()
,如果您对正则表达式不满意,则会更容易。
答案 1 :(得分:0)
找到一种方法,现在,425 ans 350可以是任何值,并引用单引号或双引号:
<?php
$embed = "<iframe width=\"425\" height=\"350\" frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://maps.google.com.br/maps?f=q&source=s_q&hl=pt-BR&geocode=&q=R.+Alm%C3%A9ria,+242+-+Penha,+S%C3%A3o+Paulo+-+S%C3%A3o+Paulo&aq=0&oq=Rua++Almeria&sll=-14.239424,-53.186502&sspn=79.602428,135.263672&t=h&ie=UTF8&hq=&hnear=R.+Alm%C3%A9ria,+242+-+Penha,+S%C3%A3o+Paulo,+03654-000&z=14&ll=-23.524401,-46.518859&output=embed'></iframe><br /><small><a href='https://maps.google.com.br/maps?f=q&source=embed&hl=pt-BR&geocode=&q=R.+Alm%C3%A9ria,+242+-+Penha,+S%C3%A3o+Paulo+-+S%C3%A3o+Paulo&aq=0&oq=Rua++Almeria&sll=-14.239424,-53.186502&sspn=79.602428,135.263672&t=h&ie=UTF8&hq=&hnear=R.+Alm%C3%A9ria,+242+-+Penha,+S%C3%A3o+Paulo,+03654-000&z=14&ll=-23.524401,-46.518859' style='color:#0000FF;text-align:left'>Exibir mapa ampliado</a></small>";
var_dump($embed);
$new = preg_replace("/\bwidth='(.*?)'/", "width='100'", $embed);
$new2 = preg_replace("/\bheight='(.*?)'/", "height='100'", $new);
$new3 = preg_replace("/\bwidth=\"(.*?)\"/", "width='100'", $new2);
$new4 = preg_replace("/\bheight=\"(.*?)\"/", "height='100'", $new3);
var_dump($new4);
?>