jquery - Php page display some strange symbols instead of BULLETED LISTS from CSV file?

268

I am retrieving some data from mysql everything is fine data fetched from database and display on page. but, their is some issue I want to display data line by line as a BULLETED LISTS as I insert data in mysql table's column features. But it is not shown same on page why ? or how can I retrieve bulleted list type data to php page ? I searching too much but not find any specific answer.

BULLETED LISTS data in features column

My Php Code :

<div >
 <p >Features :</p>
 <pre >'.$userfeatures.'</pre>
</div>

Output on php page :

Strange symbols on php page

258

Answer

Solution:

This is because different text-encoding (character set) is being used in your database and the text document displaying the bulleted list.

You should set you database and documents to use the same character set, usually UTF8.

For the database, you can do it in PHPMyAdmin, or if you are using PHP mysqli you can use the following PHP code:

$db->set_charset("utf8")

In your documents, save with encoding UTF-8.

However, as pointed out in the comments, you should also separate out your data and presentation. The database should only hold data, your application decides how it should be displayed. Consider a situation where your app might need to display the data somewhere else, maybe with a different bullet?

As Saurabh says, save your data without bullets on separate lines. Then display them using:

echo '<ul><li>' . str_replace("\n", '</li><li>', $lines) . '</li></ul>'

Also, it would be a good idea to put your styling into a separate CSS file.

982

Answer

Solution:

This means, there are different encodings.

In HTML you have to put

<meta charset="utf-8"> 

at the beginning,in PHP you have to add

$db->set_charset("utf8");

and at your database you have to set your charset also as utf-8-general.

Then it should work :)

People are also looking for solutions to the problem: loop within loop in PHP MySQL

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.