我有这个表格:
<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 ),并将其粘贴到当我按下“嵌入视频”按钮时弹出的提示输入框中。由于我的iVideo()函数,视频出现在我的index.php页面上的iframe中(在那里我有"richTextField“iframe),我可以播放它(到目前为止没有问题)。然后我按下submit按钮,我的iframe的内容出现在"my_parse_file.php“中,但没有来自Vimeo的嵌入的iframe。我查看了"my_parse_file.php“的源代码,我看到视频的iframe代码仍然在那里,它有所有的属性,但src属性是空的(src="")。这是因为stripslashes()函数应该删除表单提交后产生的反斜杠(据我所知),但由于某种原因,这似乎删除了src属性中的链接。
我尝试像这样删除stripslashes()函数:
echo '<h2>You posted:</h2><hr/>'.$_POST['title'].'<hr/>'.$_POST['myTextArea'];但是src属性看起来像这样:
src="\"//player.vimeo.com/video/15077261\""这个也不是很好。
我该怎么做才能得到一个“干净”的src?
原始源:
//player.vimeo.com/video/15077261所需输出:
<iframe src="//player.vimeo.com/video/15077261" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>发布于 2014-12-12 23:17:17
我想通了。似乎\“是需要删除的额外字符,所以我使用str_replace()将其替换为whit;
echo '<h2>You posted:</h2><hr/>'.$_POST['title'].'<hr/>'.str_replace('\"','',$_POST['myTextArea']);https://stackoverflow.com/questions/27445559
复制相似问题