[英]Removing unwanted codes from mysgli query result
please help. 请帮忙。
I was trying to query a mysqli database to display part of my blog articles on my main page using php. 我试图查询mysqli数据库,以使用php在我的主页上显示部分博客文章。 It output a messy character as shown on the link.
如链接所示,它将输出一个混乱的字符。 www.myimcm.com (unwanted commas and stuffs like that. The simple code for this was:
www.myimcm.com(不需要的逗号和类似的东西。简单的代码是:
$q ="SELECT SUBSTRING_INDEX(post_content,' ',130) AS post,(post_title) AS title,ID AS id FROM wp_posts WHERE post_type='post' ORDER BY post_date DESC LIMIT 1";
$r = @mysqli_query ($dbc, $q); // Run the query.
if ($r) { // If it ran OK, display the records.
echo '<h2>LATEST FROM OUR GUIDES</h2>';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo"<p class='title'>". ($row['title'])."</p>";
echo nl2br($row['post']);
echo '<a href="http://guides.myimcm.com/wp"> Continue reading</a>';
}
mysqli_free_result ($r); // Free up the resources.
} else { // If it did not run OK.
// Public message:
echo '<p class="error">The are no latest from our blog. We apologize for any inconvenience.</p>';
// Debugging message:
echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
} // End of if ($r) IF.
mysqli_close($dbc); // Close the database connection.
use utf-8 encoding in your webpages. 在网页中使用utf-8编码。 Use this code in your head section.
在您的头部使用此代码。
header("Content-Type: text/html; charset=utf-8");
Your page claims to be encoded in UTF-8, but that is not true. 您的页面声称是用UTF-8编码的,但事实并非如此。 It contains the following octets:
85
, 91
, 92
, a0
which (on their own) are not valid UTF-8. 它包含以下字节:
85
, 91
, 92
, a0
这(对自己)是无效的UTF-8。 They are probably from one of the Windows-125x character encodings, such as Windows-1252 . 它们可能来自Windows-125x字符编码之一,例如Windows-1252 。
You need to set up your database to use the correct character encoding for the Database, Table, and connection. 您需要设置数据库以对数据库,表和连接使用正确的字符编码。 See the MySQL manual and PHP manual for details.
有关详细信息,请参见MySQL手册和PHP手册 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.