0

ダイナミックHTMLテーブルからCSVにデータをエクスポートしています。

ただし、データに制御文字などが含まれている場合があるため、これにより問題が発生します。

可能であれば、これらすべてを取り除くか、「フレンドリー」にする必要がありますか?

私はこれを行う方法がわからないので、誰かが助けることができますか?

これが私のスクリプトです:

<textarea name="siteurl" rows="10" cols="50">
<?php //Check if the form has already been submitted and if this is the case, display the     submitted content. If not, display 'http://'.
echo (isset($_GET['siteurl']))?htmlspecialchars($_GET['siteurl']):"http://";?>
</textarea><br>
<input type="submit" value="Submit">
</form>
</div>
<div id="nofloat"></div>
<table class="metadata" id="metatable_1">
<?php
error_reporting(E_ALL);
//ini_set( "display_errors", 0);
function parseUrl($url){
    //Trim whitespace of the url to ensure proper checking.
    $url = trim($url);
    //Check if a protocol is specified at the beginning of the url. If it's not,    prepend 'http://'.
    if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
            $url = "http://" . $url;
    }
    //Check if '/' is present at the end of the url. If not, append '/'.
    if (substr($url, -1)!=="/"){
            $url .= "/";
    }
    //Return the processed url.
    return $url;
}
//If the form was submitted
if(isset($_GET['siteurl'])){
    //Put every new line as a new entry in the array
    $urls = explode("\n",trim($_GET["siteurl"]));
    //Iterate through urls
    foreach ($urls as $url) {
            //Parse the url to add 'http://' at the beginning or '/' at the end if not    already there, to avoid errors with the get_meta_tags function
            $url = parseUrl($url);
            //Get the meta data for each url
            $tags = get_meta_tags($url);
            //Check to see if the description tag was present and adjust output    accordingly
            $tags = NULL;
$tags = get_meta_tags($url);
if($tags)
echo "<tr><td>Description($url)</td><td>" .$tags['description']. "</td></tr>";
else 
echo "<tr><td>Description($url)</td><td>No Meta Description</td></tr>";
    }
}
?>
</table>
<script type="text/javascript">
        var exportTable1=new ExportHTMLTable('metatable_1');
    </script>
<div>
        <input type="button" onclick="exportTable1.exportToCSV()"   value="Export to CSV"/>
        <input type="button" onclick="exportTable1.exportToXML()"     value="Export to XML"/>
    </div>

</body>
4

2 に答える 2

1

質問を正しく理解しているかどうかはわかりませんが、UTF-8でエンコードされたCSVだけが必要utf8_encode()な場合は、ファイルに書き込んでいるデータに使用できます。

または、制御文字を省略したい場合は、ctype_cntrl()...を使用してファイルに書き込む前に、制御文字の行を確認してから、正規表現を使用してそれらを削除するか、行をすべて一緒に書き込むことを拒否することができます。 。

于 2012-04-12T21:10:18.500 に答える
1

私はあなたが次のようなものが欲しいと思います:
echo "<tr><td>Description($url)</td><td>" . utf8_encode($tags['description']) . "</td></tr>";

間違って表示されているテキストを指定してください$tags['description']

おそらく必要な関数のマニュアルは次のとおりです:mb_convert_encodingutf8_encode

于 2012-04-13T10:58:58.147 に答える