[英]Removing unwanted codes from mysgli query result
请帮忙。
我试图查询mysqli数据库,以使用php在我的主页上显示部分博客文章。 如链接所示,它将输出一个混乱的字符。 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.
在网页中使用utf-8编码。 在您的头部使用此代码。
header("Content-Type: text/html; charset=utf-8");
您的页面声称是用UTF-8编码的,但事实并非如此。 它包含以下字节: 85
, 91
, 92
, a0
这(对自己)是无效的UTF-8。 它们可能来自Windows-125x字符编码之一,例如Windows-1252 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.