对 iframe 进行编号并显示
Number the iframes and display it
我有一段代码读取 space 从输入字符串中分离出的 URL,并将它们替换为 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>
做这样的事情,我想你把 $nrr = 1 放在你的循环中所以每次循环 运行 它变成 1.
<?php
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$nrr = 1;
// output data of each row
while ($row = $result->fetch_assoc()) {
$nr = $row['nr'];
$playery = $row['player'];
$nrplayer = $nrplayer++;
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);
while (mb_substr($playery, 0, 1) == " ") {
$playery = substr($playery, 1);
}
while (mb_substr($playery, 0, -1) == " ") {
echo "ok";
$playery = substr($playery, 1);
}
require("ads.php");
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) . "'>";
}
}
?>
in php $var++/$var-- 表达式在封装它的语句之后执行,所以 $nrr 直到你的 echo
之后才会增加
$var = 1;
echo $var++; //1
echo $var; //2
我有一段代码读取 space 从输入字符串中分离出的 URL,并将它们替换为 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>
做这样的事情,我想你把 $nrr = 1 放在你的循环中所以每次循环 运行 它变成 1.
<?php
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$nrr = 1;
// output data of each row
while ($row = $result->fetch_assoc()) {
$nr = $row['nr'];
$playery = $row['player'];
$nrplayer = $nrplayer++;
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);
while (mb_substr($playery, 0, 1) == " ") {
$playery = substr($playery, 1);
}
while (mb_substr($playery, 0, -1) == " ") {
echo "ok";
$playery = substr($playery, 1);
}
require("ads.php");
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) . "'>";
}
}
?>
in php $var++/$var-- 表达式在封装它的语句之后执行,所以 $nrr 直到你的 echo
之后才会增加$var = 1;
echo $var++; //1
echo $var; //2