Php 在另一个字符串中插入从选定字符到选定字符的字符串
我有一个场景,需要在每个iframe的src属性之后追加Php 在另一个字符串中插入从选定字符到选定字符的字符串,php,Php,我有一个场景,需要在每个iframe的src属性之后追加&wmode=transparent 我需要替换此代码: <iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe> 对此(请注意youtube url的结尾): 非常感谢 您可以使用DOM解析器来完成以下任务: $str = <
&wmode=transparent
我需要替换此代码:
<iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe>
对此(请注意youtube url的结尾):
非常感谢 您可以使用DOM解析器来完成以下任务:
$str = <<<HTML
<iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe>
HTML;
$dom = new DOMDocument();
$dom->loadHTML($str);
foreach($dom->getElementsByTagName('iframe') as $iframe) {
$src = $iframe->getAttribute('src');
$src .= '?wmode=transparent'; // use a regex for better results
$iframe->setAttribute('src', $src);
}
echo $dom->saveHTML();
$str=getAttribute('src');
$src.='?wmode=transparent';//使用正则表达式可以获得更好的结果
$iframe->setAttribute($src',$src);
}
echo$dom->saveHTML();
您可以使用DOM解析器来完成以下任务:
$str = <<<HTML
<iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe>
HTML;
$dom = new DOMDocument();
$dom->loadHTML($str);
foreach($dom->getElementsByTagName('iframe') as $iframe) {
$src = $iframe->getAttribute('src');
$src .= '?wmode=transparent'; // use a regex for better results
$iframe->setAttribute('src', $src);
}
echo $dom->saveHTML();
$str=getAttribute('src');
$src.='?wmode=transparent';//使用正则表达式可以获得更好的结果
$iframe->setAttribute($src',$src);
}
echo$dom->saveHTML();
您可以使用DOM解析器来完成以下任务:
$str = <<<HTML
<iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe>
HTML;
$dom = new DOMDocument();
$dom->loadHTML($str);
foreach($dom->getElementsByTagName('iframe') as $iframe) {
$src = $iframe->getAttribute('src');
$src .= '?wmode=transparent'; // use a regex for better results
$iframe->setAttribute('src', $src);
}
echo $dom->saveHTML();
$str=getAttribute('src');
$src.='?wmode=transparent';//使用正则表达式可以获得更好的结果
$iframe->setAttribute($src',$src);
}
echo$dom->saveHTML();
您可以使用DOM解析器来完成以下任务:
$str = <<<HTML
<iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe>
HTML;
$dom = new DOMDocument();
$dom->loadHTML($str);
foreach($dom->getElementsByTagName('iframe') as $iframe) {
$src = $iframe->getAttribute('src');
$src .= '?wmode=transparent'; // use a regex for better results
$iframe->setAttribute('src', $src);
}
echo $dom->saveHTML();
$str=getAttribute('src');
$src.='?wmode=transparent';//使用正则表达式可以获得更好的结果
$iframe->setAttribute($src',$src);
}
echo$dom->saveHTML();
您可以使用dom解析器轻松完成工作。我将使用本机php dom解析器:
所以php代码看起来像
$doc = new DOMDocument();
$doc->loadHTML($your_html);
foreach($doc->getElementsByTagName('iframe') as $iframe)
{
$iframe->setAttribute("src",$iframe->getAttribute('src').'?wmode=transparent');
}
echo $doc->saveHTML();
您可以使用dom解析器轻松完成这项工作。我将使用本机php dom解析器: 所以php代码看起来像
$doc = new DOMDocument();
$doc->loadHTML($your_html);
foreach($doc->getElementsByTagName('iframe') as $iframe)
{
$iframe->setAttribute("src",$iframe->getAttribute('src').'?wmode=transparent');
}
echo $doc->saveHTML();
您可以使用dom解析器轻松完成这项工作。我将使用本机php dom解析器: 所以php代码看起来像
$doc = new DOMDocument();
$doc->loadHTML($your_html);
foreach($doc->getElementsByTagName('iframe') as $iframe)
{
$iframe->setAttribute("src",$iframe->getAttribute('src').'?wmode=transparent');
}
echo $doc->saveHTML();
您可以使用dom解析器轻松完成这项工作。我将使用本机php dom解析器: 所以php代码看起来像
$doc = new DOMDocument();
$doc->loadHTML($your_html);
foreach($doc->getElementsByTagName('iframe') as $iframe)
{
$iframe->setAttribute("src",$iframe->getAttribute('src').'?wmode=transparent');
}
echo $doc->saveHTML();
非常感谢你的意见。我自己找到了一个解决方案,使用了一些字符串替换函数
<?php
$videoEmbedCode = '<iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe>';
$appendString = '/?wmode=transparent';
/* Youtube video sticky menu overlap fix */
$searchStartLen = strpos($videoEmbedCode, 'youtube');
$searchEndLen = strpos($videoEmbedCode, '"', $searchStartLen);
$newVideoEmbedCode = substr_replace($videoEmbedCode, $appendString, $searchEndLen, 0);
print $newVideoEmbedCode;
?>
成功了 非常感谢您的意见。我自己找到了一个解决方案,使用了一些字符串替换函数
<?php
$videoEmbedCode = '<iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe>';
$appendString = '/?wmode=transparent';
/* Youtube video sticky menu overlap fix */
$searchStartLen = strpos($videoEmbedCode, 'youtube');
$searchEndLen = strpos($videoEmbedCode, '"', $searchStartLen);
$newVideoEmbedCode = substr_replace($videoEmbedCode, $appendString, $searchEndLen, 0);
print $newVideoEmbedCode;
?>
成功了 非常感谢您的意见。我自己找到了一个解决方案,使用了一些字符串替换函数
<?php
$videoEmbedCode = '<iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe>';
$appendString = '/?wmode=transparent';
/* Youtube video sticky menu overlap fix */
$searchStartLen = strpos($videoEmbedCode, 'youtube');
$searchEndLen = strpos($videoEmbedCode, '"', $searchStartLen);
$newVideoEmbedCode = substr_replace($videoEmbedCode, $appendString, $searchEndLen, 0);
print $newVideoEmbedCode;
?>
成功了 非常感谢您的意见。我自己找到了一个解决方案,使用了一些字符串替换函数
<?php
$videoEmbedCode = '<iframe width="560" height="315" src="//www.youtube.com/embed/UPk1B1bxUPg" frameborder="0" allowfullscreen></iframe>';
$appendString = '/?wmode=transparent';
/* Youtube video sticky menu overlap fix */
$searchStartLen = strpos($videoEmbedCode, 'youtube');
$searchEndLen = strpos($videoEmbedCode, '"', $searchStartLen);
$newVideoEmbedCode = substr_replace($videoEmbedCode, $appendString, $searchEndLen, 0);
print $newVideoEmbedCode;
?>
成功了 这似乎也是非常好的代码。我一定会在将来使用它。这似乎也是很好的代码。我一定会在将来使用它。这似乎也是很好的代码。我一定会在将来使用它。这似乎也是很好的代码。我将来一定会用它。这也是一个很好的方法。我自己找到了另一个解决方案,并在下面添加了一条评论。谢谢,不客气。我强烈建议您在处理html时使用解析器。这也是一种很好的方法。我自己找到了另一个解决方案,并在下面添加了一条评论。谢谢,不客气。我强烈建议您在处理html时使用解析器。这也是一种很好的方法。我自己找到了另一个解决方案,并在下面添加了一条评论。谢谢,不客气。我强烈建议您在处理html时使用解析器。这也是一种很好的方法。我自己找到了另一个解决方案,并在下面添加了一条评论。谢谢,不客气。我强烈建议您在使用html时使用解析器。