简体   繁体   中英

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. 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:

 $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. 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. It contains the following octets: 85 , 91 , 92 , a0 which (on their own) are not valid UTF-8. They are probably from one of the Windows-125x character encodings, such as 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM