English 中文(简体)
在PHP书内将案文转至UTF-8
原标题:Converting text to UTF-8 within PHP script
  • 时间:2012-04-12 21:02:02
  •  标签:
  • php
  • html

我正在从一个动态的html表向CSV出口数据。

然而,这造成了一些问题,因为有时数据具有控制特征等。

我需要所有被 stripped弃或尽可能友好的人?

我不知道如何这样做,谁能帮助?

这里是我的文字:

<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("
",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>
最佳回答

I m guessing you want something like:
echo "<tr><td>Description($url)</td><td>" . utf8_encode($tags[ description ]) . "</td></tr>";

请具体说明显示错误的案文是$tag[说明?

http://php.net/manual/en/Function.mb-convert-encoding.php rel=“nofollow”>mb_convert_encoding ,utf8_encode

问题回答

如果我能正确理解这个问题,但如果你想要的是UTF-8编码的CSV,你只能使用utf8_encode()。

或者,如果你想要放弃控制果园,你可以先检查控制果园的线,然后使用<条码>c 型_cntrl(),然后使用定期表达来消除这些果园,或拒绝共同写上所有线。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签