Hello! Help, please, make a regular schedule. There is something like this code.

<p><iframe src="http://www.youtube.com/embed/3SEDJSYob_s" frameborder="0" height="350" width="425"></iframe></p> 

You need to cut out <p> and change the height and width to the values ​​of the preset variables.

  • there is no just cut them - Danis92

1 answer 1

Cut something without problems

 $width=1300; $height=169; preg_match_all('~(?<=<p>)<iframe.*</iframe>(?=</p>)~Uis',$htm,$arr); $ifr=preg_replace('~(.*height=")[\d]+(" width=")[\d]+(")~i','$1%2$d$2%1$d$3',$arr[0][0]); // если иной порядок параметров $ifr=preg_replace('~(.*width=")[\d]+(" height=")[\d]+(")~i','$1%1$d$2%2$d$3',$ifr); // меняем "высоту"/"ширину" $ifr=sprintf($ifr,$width,$height); echo $ifr; // тут iframe 

not the most elegant code, but convenient

principle: we cut out <p> replace the width and height values ​​with descriptors. What for? I suppose html will be stored in the database, so the processed html to $ifr=sprintf($ifr,$width,$height); save And when you need to display a video of the desired size, we call sprintf indicating the desired height and width.

  • For example, I will have several video options on my site, the preview will display the minimum size of 300x169, when you go to the page, the size is different. Values ​​will be stored in variables, and now instead of height = "350" width = "425" we substitute these variables - Danis92
  • What does the regular season do with it? Use any template maker, or at worst, write where it will be easier to live. Yes, even on a primitive str_replace: $ template = str_replace (' PREVIEW_WIDTH ', '300', $ template); - user6550