0

我有这个表格:

<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),我可以播放它(到目前为止没问题)。然后我按下提交按钮,我的 iframe 的内容出现在“my_parse_file.php”中,但没有来自 Vimeo 的嵌入 iframe。我查看了“my_parse_file.php”的源代码,发现视频的 iframe 代码还在,它具有所有属性,但 src 属性为空(src="")。那是因为 stripslashes() 函数应该删除表单提交后产生的反斜杠(据我所知),

我试图像这样删除 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>
4

1 回答 1

0

I figured it out. It Seemed like that \" is the extra character that needs to be removed. So I replaced it whit nothing using str_replace();

echo '<h2>You posted:</h2><hr/>'.$_POST['title'].'<hr/>'.str_replace('\"','',$_POST['myTextArea']);
于 2014-12-12T15:17:17.263 回答