我有这样的表格:
<form action="my_parse_file.php" name="myform" id="myform" method="post">
<input placeholder="Entry Title" style="height: 25px; text-align: center; font-size: 12px; background-color: #151515; color: #B4B4B4; border: 1px solid #303030;"
name="title" id="title" type="text" size="80" maxlength="80" />
<br />
<p>
Entry Body:<br />
<div id="wysiwyg_cp" style="padding: 8px; width: 700px; margin: 0px auto;">
<input class="BTN2" type="button" onclick="iBold()" value="B" />
<input class="BTN2" type="button" onclick="iUnderline()" value="U" />
<input class="BTN2" type="button" onclick="iItalic()" value="I" />
<input class="BTN2" type="button" onclick="iFontSize()" value="Text Size" />
<input class="BTN2" type="button" onclick="iForeColor()" value="Text Color" />
<input class="BTN2" type="button" onclick="iHorizontalRule()" value="HR" />
<input class="BTN2" type="button" onclick="iUnorderedList()" value="UL" />
<input class="BTN2" type="button" onclick="iOrderedList()" value="OL" />
<input class="BTN2" type="button" onclick="iLink()" value="Link" />
<input class="BTN2" type="button" onclick="iUnLink()" value="UnLink" />
<input class="BTN2" type="button" onclick="iImage()" value="Image" />
<input class="BTN2" type="button" onclick="iVideo()" value="Embed Video" />
</div>
<!-- Hide (but keep) your normal textarea and place it in the iFrame replacement for it -->
<textarea style="display: none;" name="myTextArea" id="myTextArea" cols="100" rows="14"></textarea>
<iframe onload="this.contentWindow.focus()" name="richTextField" id="richTextField" style="border: 1px solid #303030; background-color: #151515; width: 700px; height: 300px;"></iframe>
<!-- End replacing your normal textarea -->
</p>
<br />
<br />
<input name="myBtn" type="button" value="Submit Data" onclick="javascript: submit_form();" />
</form>
这是iVideo()函数:
function iVideo(){
var vidSrc = prompt('Enter video embed code:','');
var iframe = document.getElementById('richTextField').contentDocument;
iframe.writeln("<br/>"+vidSrc);
}
submit_form()函数:
function submit_form(){
var theForm = document.getElementById("myform");
theForm.elements["myTextArea"].value = window.frames['richTextField'].document.body.innerHTML;
theForm.submit();
}
这是my_parse_file.php:
<?php
echo '<h2>You posted:</h2><hr/>'.$_POST['title'].'<hr/>'.stripslashes($_POST['myTextArea']);
?>
我去告诉Vimeo,拿一个视频的嵌入代码(也是一个iframe)并将其粘贴到提示输入框中,当我按下&#34;嵌入视频&#时弹出34;按钮。由于我的iVideo()函数,视频出现在我的index.php页面上的iframe(我有&#34; richTextField&#34; iframe),我可以播放它(直到现在都没问题)。然后我按下提交按钮,我的iframe的内容出现在&#34; my_parse_file.php&#34;,但没有来自Vimeo的嵌入式iframe。我查看了&#34; my_parse_file.php&#34;的源代码。我看到视频的iframe代码仍然存在,它具有所有属性,但src属性为空(src =&#34;&#34;)。而且这是因为stripslashes()函数应该删除表单提交后产生的反斜杠(据我所知),但似乎由于某种原因这会从我的src属性中删除链接。
我试图删除stripslashes()函数,如下所示:
echo '<h2>You posted:</h2><hr/>'.$_POST['title'].'<hr/>'.$_POST['myTextArea'];
但是src属性看起来像这样:
src="\"//player.vimeo.com/video/15077261\""
这个也不好。
我该怎样做才能得到一个&#34;清洁&#34; SRC?
原文src:
//player.vimeo.com/video/15077261
期望的输出:
<iframe src="//player.vimeo.com/video/15077261" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
答案 0 :(得分:0)
我明白了。它看起来像那样\&#34;是需要删除的额外字符。所以我使用str_replace();
替换它echo '<h2>You posted:</h2><hr/>'.$_POST['title'].'<hr/>'.str_replace('\"','',$_POST['myTextArea']);