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 ページ (「richTextField」iframe がある場所) の 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

私はそれを考え出した。\" は削除する必要がある余分な文字のようです。そのため、str_replace(); を使用して何も置き換えませんでした。

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