0

这是我的 HTML 代码:

<img src="http://img.youtube.com/vi/ErIRt52MOkE/0.jpg" class="mceItem" alt="ErIRt52MOkE"/>

我想像这样转换这段代码:

<iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/ErIRt52MOkE" frameborder="0" allowfullscreen></iframe>

这是我的模式:(Message: preg_replace() [function.preg-replace]: Unknown modifier 'v'

<img(?=[^>]+?class="mceItem")(?=[^>]+?alt="[\w]+?")[^>]+?img.youtube.com/vi/([\w]+?)/0.jpg[^>]*?/>
4

1 回答 1

0

尝试这个:-

<?php
  preg_match_all('%youtube\.com\/vi\/([^\/]+)%','<img src="http://img.youtube.com/vi/ErIRt52MOkE/0.jpg" class="mceItem" alt="ErIRt52MOkE"/>',$matches);

  print_r($matches);

  $outputStr = '<iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/'.$matches[1][0].'" frameborder="0" allowfullscreen></iframe>';

  echo $outputStr;
?>
于 2012-04-29T09:38:26.550 回答