基本上我收到的是:
<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="引号或双引号内的任何值。
我不擅长正则表达式,尝试用这个来学习似乎很复杂。
知道吗?
谢谢。
不久前我回答了一个类似的问题->如何使用php替换iframe html标记的宽度和高度?
更好地使用str_replace()
,它更容易,尤其是当您对正则表达式不熟悉时。
找到一种方法,现在,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);
?>