我有一段代码从输入字符串中读取空格分隔的URL,并用iframe
视频替换它们。我想在它们上面插入iframe
的编号。对iframe进行编号并显示它
下面是我的代码:
$result = $conn - > query($sql);
if ($result - > num_rows > 0) {
// output data of each row
while ($row = $result - > fetch_assoc()) {
$nr = $row['nr'];
$playery = $row['player'];
$nrplayer = $nrplayer++; //old int (not used)
//////remove from string all iframes and replace tons spaces to only one before every url (That makes string more clear)//////
while (strpos($playery, ' ') !== false) {
$playery = str_replace(" ", "", $playery);
}
$playery = str_replace("http", " http", $playery);
$playery = str_replace('<iframewidth="420"height="315"src="', ' ', $playery);
$playery = str_replace('<iframesrc="', ' ', $playery);
////////remove space of front and in the back ////////
while (mb_substr($playery, 0, 1) == " ") {
$playery = substr($playery, 1);
}
while (mb_substr($playery, 0, -1) == " ") {
echo "ok";
$playery = substr($playery, 1);
}
//////add some ads on page////////
require("ads.php");
//////create iframes///////
$nrr = 1;
echo $nrr."<br><br><br> <iframe allowfullscreen='1' width='800' height='500' src='".str_replace(' ', "'></iframe> ".$nrr++." <br><br><br> <iframe allowfullscreen='1' width='800' height='500' src='", $playery)."'>";
}
}
我也只拿到了1行字符串的值$playery
是
$playery = "http://www.dailymotion.com/swf/x2t2mgd http://www.dailymotion.com/swf/x2t2ury https://drive.google.com/file/d/0B4DzuaeCNhcsdlhnLURaU0dBQTg/preview https://drive.google.com/file/d/0B6ORWPhIsXTCUVpMd0RNTFU3Wk0/preview https://drive.google.com/file/d/0B9x5eo1ro_r9UVZZSVJucGtJbGs/preview http://mp4upload.com/embed-t9ve1iot81so.html"
我的代码,我得到的是这样的输出:
1
<video>
1
<video>
1
<video>
1
<video>
不过,我要得到这样的:
1
<video>
2
<video>
3
<video>
4
<video>
后,如果用'echo'行应该是结果(这并不真正符合你的例子在上面给出) - 那么你只在输出'$ nrr =中使用这个变量1;'(当然它总是“1”)。你可能想使用'$ nrplayer'。但是你的代码不太可读,也许你需要提供更多的信息。 – Risadinha
编辑。我添加了评论 – Doknes
我改进了代码的格式并重新措辞了句子以更好地解释问题。格式不正确的代码难以阅读,并将可能回答您问题的人赶走。请查看[编辑帮助](http://stackoverflow.com/editing-help)获取更多格式化信息。我也修改了标题。 – Harry