Pergunta

I want to remove from server-side (php) the iframe tag of an embedded Google Map.

It's a symfony 1.4 project and I want to remove this from the action before serving the html to the response.

The tag looks something like this. At first glance it seems a task to be solved using regex.

<p>
<iframe width="425" height="350" src="http://maps.google.com/maps/ms?hl=en&amp;mpa=0&amp;ctz=-60&amp;mpf=0&amp;ie=UTF8&amp;msa=0&amp;t=m&amp;vpsrc=6&amp;msid=207463975658802969656.0004b1369c88b98702faa&amp;ll=44.705998,8.068085&amp;spn=0.085403,0.145912&amp;z=12&amp;iwloc=0004b136a142301cefe0c&amp;output=embed"></iframe>
<br><small>View <a href="http://maps.google.com/maps/ms?hl=en&amp;mpa=0&amp;ctz=-60&amp;mpf=0&amp;ie=UTF8&amp;msa=0&amp;t=m&amp;vpsrc=6&amp;msid=207463975658802969656.0004b1369c88b98702faa&amp;ll=44.705998,8.068085&amp;spn=0.085403,0.145912&amp;z=12&amp;iwloc=0004b136a142301cefe0c&amp;source=embed">Test</a>
in a larger map</small>
</p>

Is there any other solution or a valid regex which could do this?

I would like only the <iframe> tag to be removed if possible

Foi útil?

Solução

You could use preg_replace():

echo preg_replace("#<p>(.*)<iframe(.*?)maps.google.com(.*?)</iframe>(.*)</p>#is", '', $string);

Codepad Example

Outras dicas

Try this:

preg_replace('/<iframe.*?\/iframe>/i','', $this->product->description);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top