2010-07-22 7 views
0

J'utilise PHP & veulent analyser la chaîne donnée: Disons quechaîne de Parsing en utilisant PHP

$str = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/W-WKYIgGBbU&amp;hl=en_US&amp;fs=1"></param><param 
name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param> 
<embed src="http://www.youtube.com/v/W-WKYIgGBbU&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" 
allowfullscreen="true" width="100" height="100"></embed> 
</object>'; 

et j'ai juste besoin

$output = '<embed src="http://www.youtube.com/v/W-WKYIgGBbU&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" 
allowfullscreen="true" width="100" height="100"></embed>'; 

et régler la hauteur et la largeur de ma valeur personnalisée laisser dire $ width = 30 et $ height = 40.

Merci ..

Répondre

2

Cela devrait fonctionner:

preg_match("/<embed.*\/embed>/mi",$str,$matches); 
$output = preg_replace(array('/width="\d+"/i','/height="\d+"/i'),array('width="30"','height="40"'),$matches[0]); 
+0

Merci mon pote ça marche vraiment et c'est excellent .............. 1000s de mercis encore .. –

0

Vous pouvez analyser HTML en utilisant Tidy et SimpleXML:

  1. propre HTML avec Tidy
  2. Trouvez et modifier < intégrer tag > avec SimpleXML
0

je ferais quelque chose comme ça

<?php 

$string = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/W-WKYIgGBbU&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/W-WKYIgGBbU&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100" height="100"></embed></object>'; 
$pattern = '/.*src="(.*?)".*/'; 
$replacement = '<embed src="\\1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100" height="100"></embed>'; 
echo preg_replace($pattern, $replacement, $string); 

?>