How can I strip out the string like � in php? - php

How can I vanish out the odd string like � in php?
I already use like html_entity_decode php function but it's still not works.

Try to add these line in your db config file.
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_set_charset('utf8',$con);
mysql_select_db("db_name", $con);
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />

� isn't just one symbol -- it's the symbol used to replace a symbol that your browser can't make sense of. Usually this is caused by encoding issues -- you set the wrong encoding, or someone is using a symbol from a different encoding.
You can't just magically strip it out, because it isn't just one character. Simply put, encoding is one place where you can't just wave a magic wand -- you have to decide on an encoding, and then enforce it.
If you're taking user input, I honestly don't have any clue how to help with the issue. You can check for common causes (curly quotes and dashes as distinct from hyphens are where I run into this the most), and force a manual replace on them, but if a user wants to enter in a badly-encoded character, there's not a lot you can do.

Try changing your <meta charset to iso-8859-1 like
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

If your content is in ANSI encoding use
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
you can check the encoding of your files using a editor like ( NOTEPAD ++ )

Related

SQL / PHP returns accents into codes and cant read the charset

I've got a problem with my charset I guess.
I've called out this line of code on the top of my file.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
when I try to read out an 'ë' it returns these two characters: ë .
I can't figure out what I have to do, to return the accented character.
I also found out it only happens to be when I put the accented character into <h1> tags.
Try adding this extra tag so it looks like this:
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
If the data is in a file (I guess an html file) then this may help: http://www.thedatastudio.net/character_encoding_profile.htm.
What are you reading the file with? As you suggest, I'm sure it's interpreting the file as if it were in a different character encoding.
If you are reading data from mysql database then you can use mysqli_set_charset() for mysqli or if you are using PDO you can try below code.
$dbh = new PDO('mysql:'.$conn, $username, $password);
$dbh->exec("set names utf8");

Two webpages displaying differently special spanish characters

I have a website where the web pages feed from the same database and I found that in two webpages that have same queries they interpretate the spanish special characters differently.
I cant really figure out what is wrong as I have stripped out the code which is interpreting the special spanish characters wrong and building it up from the scratch.
This one interpretes the characters well.
http://amragl.com/
This one interpretes the characters wrong.
http://amragl.com/menu.php
They both have the following
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
They both feed from the same database and use same queries.
Does anyone have any idea of how to fix this problem?
Thanks in advance.
--UPDATE-
PEASE SEE THE WORD "GAZPACH" or "AL LIM" to see the difference.
You have both
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
in the same file.
I suggest only using the utf-8 one.
Change iso-8859-1 to utf-8, should fix it.
The menu.php page is rendering with windows-1252 encoding, even tho it has iso-8859-1 set.
Are the menu.php contents coming from a database? If yes, which encoding is the database using?

trouble with non-latin characters

I'm having some trouble with my page. I have moved my site from a host provider to another one, and now i'm having some problems with non-latin characters, for text that comes from db query and for text that is in html/php file.
For text that comes from db someone suggested me to apply this after db connection:
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
and it did the trick, but, now i'm having the same problem for texts that comes from html/php files: instead of ë or ç appears �
I'm sure that should be e trick someone on the server or somewhere else on the configuration.
Hope that you can help me.
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
i'm using at the header of my file.
You must have this line in your <head> section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Is the collation of your database where the data is stored in utf8_general_ci?
Maybe there was a problem while transfering the files.
If you are familiar with Linux, try to fix the broken files on your server with recode
(excerpt: "The Recode library converts files between character sets and usages.")

error using php to print out special charcters from a database

Alright, what I'm trying to do is print out a few lines of text onto a page from a database, and the problem I'm running into is when it sees something like a ' in the text, it puts out a ?. So what I'm wondering is there a way around this? I know with HTML you can use special characters, but I'm working with dynamic data here. I did try doing this, but it's just not working:
<?php
include("connect.php");
$queryCurUser = "SELECT * FROM wn_current;";
$queryResult2 = mysql_query($queryCurUser, $conn) or
die ("queryResult Failed: ". mysql_error());
while ($row = mysql_fetch_array($queryResult2))
{
$body = $row['body'];
echo $row['heading'];
echo"<br/>";
if($body == "'"){
echo"hot dog";
}
echo"<br/>";
echo $row['pdflink'];
}
?>
You need to change the character set used in the database to one with more characters - UTF-8, for instance.
You need to tell the browser what encoding the data is.
Most likely this tag will solve your woes:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
If that doesn't work, try this one:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
Check the character set that your database table uses; you may want to change it to use UTF-8. Also consider using htmlentities() on your echoed output with the correct charset to convert any characters that have HTML character entity equivalents, e.g.
echo htmlentities($body, ENT_NOQUOTES, 'UTF-8', false);
If you store international characters (á, ê, etc..), not only do you need to choose the correct character encoding for your database (e.g. UTF-8), but you also need to tell the browser to use the correct character set, by way of
a meta tag:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
or a php header:
header("Content-Type: text/html; charset=utf-8");
Also, it may be necessary to specify the charset that the MySQL extension should use with mysql_set_charset().
$body=str_replace['"', """, $body]; // double quotes
seemed to work

Web page text display problem

I keep getting these weird text characters when I display user submitted text. like in the following example below. Is there a way I can fox this using PHP, CSS or something so that the characters are displayed properly?
Here is the problem text.
Problems of �real fonts� on the web. The one line summary:
different browsers and different platforms do �hinting�
Here is my meta tag.
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
It's an encoding problem. Make sure you send the correct encoding to the browser. If it's UTF-8, you'll do it like this:
header("Content-type: text/html; charset=utf-8");
Also, make sure that you store the content using the same encoding throughout the entire system. Set your database tables to utf8. If you're using MySQL, run the SET NAMES utf8 query when connecting to make sure you're running in UTF-8.
These weird characters occur when you suddenly switch encoding.
Also, some functions in PHP take a $charset parameter (e.g. htmlentities()). Make sure you pass the correct charset to that one as well.
To make sure that PHP handles your charset correctly in all cases, you can set the default_charset to utf-8 (either in php.ini or using ini_set()).
Set your page to UTF-8 encoding.
Please check with the char-set in header section.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
use this below one:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
or try this one:
htmlentities($str, ENT_QUOTES);
Could be problem with file encoding please check that your files is correctly encoded, saved as "UTF-8 without boom", also if you are saving to database use SET NAMES UTF-8

Categories