我有一段代碼從輸入字符串中讀取空格分隔的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