Reverse htmlspecialchars or something
Moderator: General Moderators
Reverse htmlspecialchars or something
I have a project that gets from mysql the data that i search.
Until 10 minutes ago, the results could not display me correctly the Greek characters from mysql.
The search system searches the title of the item which contains English and Greek characters.
I solve this problem with this :
I use notepad for any encoding i do between ansi, unicode and utf8.
I wrote into notepad the title in English and for the Greek letters i wrote them in HTML encoded characters and i saved it as ANSI.
On phpmyadmin I uploaded the file choosing utf8 for Character set of the file and ANSI for sql compatibility.
i searched for that English word i wrote in the title and displayed to me the result WITH GREEK LETTERS correctly.
This is the only way to display Greek letters. I tried everything.
The problem is :
When i searched using that Greek letters that i wrote in the title the result showed me nothing. Then i searched again using the HTML encoded characters i used for that title and i got the result with Greek letters!
Having in mind that with HTML encoded characters the system found me the result, I guess there must be a line that it will convert the Greek characters to HTML encoded characters before it gives me the results.
Anyone knows anything about this?
Until 10 minutes ago, the results could not display me correctly the Greek characters from mysql.
The search system searches the title of the item which contains English and Greek characters.
I solve this problem with this :
I use notepad for any encoding i do between ansi, unicode and utf8.
I wrote into notepad the title in English and for the Greek letters i wrote them in HTML encoded characters and i saved it as ANSI.
On phpmyadmin I uploaded the file choosing utf8 for Character set of the file and ANSI for sql compatibility.
i searched for that English word i wrote in the title and displayed to me the result WITH GREEK LETTERS correctly.
This is the only way to display Greek letters. I tried everything.
The problem is :
When i searched using that Greek letters that i wrote in the title the result showed me nothing. Then i searched again using the HTML encoded characters i used for that title and i got the result with Greek letters!
Having in mind that with HTML encoded characters the system found me the result, I guess there must be a line that it will convert the Greek characters to HTML encoded characters before it gives me the results.
Anyone knows anything about this?
Re: Reverse htmlspecialchars or something
Code: Select all
mysql_query("SET NAMES 'utf8'"); Re: Reverse htmlspecialchars or something
thank you for your reply.
Where i write that?

Where i write that?
Re: Reverse htmlspecialchars or something
<?php
$str = '<p>this -> " & & </p>';
echo htmlentities($str);
?>
this should make a work right? but why it didnt?!
$str = '<p>this -> " & & </p>';
echo htmlentities($str);
?>
this should make a work right? but why it didnt?!
Re: Reverse htmlspecialchars or something
are you trying to search the database for a greek string, or output a greek string?When i searched using that Greek letters that i wrote in the title the result showed me nothing. Then i searched again using the HTML encoded characters i used for that title and i got the result with Greek letters!
Re: Reverse htmlspecialchars or something
My greek data is written in the database using the decimal format http://htmlhelp.com/reference/html40/en ... mbols.html
The only way to get the results displayed is when i search with those decimal codes.
I want to convert the greek letters that i write in the searchbox to those decimal codes before it gives me the results, with this way i will get the correct search results.
The only way to get the results displayed is when i search with those decimal codes.
I want to convert the greek letters that i write in the searchbox to those decimal codes before it gives me the results, with this way i will get the correct search results.
Re: Reverse htmlspecialchars or something
You can make a "data dictionary" by defining an array with strings as keys, you can write a 3 line function to encode and decode based on the array
Code: Select all
function lookupSymbol( $symbol)
{
$lookup = array( 'amperstand' => '&' );
return isset($lookup[$symbol])?$lookup:$symbol;
}
echo lookupSymbol( 'amperstand' ); // outputs '&'
echo lookupSymbol( 'doesnt exist' ); // outputs 'doesnt exist'
Last edited by josh on Sat Sep 20, 2008 8:30 pm, edited 1 time in total.
Re: Reverse htmlspecialchars or something
hm.. you sound correct.
but i do not know how do it, but i will if you write me an example. thanks!
but i do not know how do it, but i will if you write me an example. thanks!
Re: Reverse htmlspecialchars or something
edited my post before you replied.
Re: Reverse htmlspecialchars or something
thank you a lot!
i hope that will work.
can I ask you something else?
This is the part of search.php that does the work ( i guess, i am 99% sure )
My question is, where i write the function?
thanks
i hope that will work.
can I ask you something else?
This is the part of search.php that does the work ( i guess, i am 99% sure )
My question is, where i write the function?
thanks
Code: Select all
<?php #//v.3.3.0
require('./includes/config.inc.php');
$NOW = date("YmdHis",mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d"),date("Y")));
if (!ini_get('register_globals')) {
$superglobales = array($_POST, $_GET);
foreach ($superglobales as $superglobal) {
extract($superglobal, EXTR_SKIP);
}
}
$q = trim($_GET['q']);
$query = "".$q;
$query = "".$query; // set $query variable if it's not set yet
$searchQuery = $query;
$qquery = ereg_replace("%","\\%",$query);
$qquery = ereg_replace("_","\\_",$qquery);
if ( strlen($query)==0 ) {
include "header.php";
include phpa_include("template_empty_search.html");
include "footer.php";
exit;
}
/* generate query syntax for searching in auction */
$search_words = explode (" ", $qquery);
/* query part 1 */
$qp1 = "";
$qp = "";
$qp1 = htmlentities($qp1);
$qp1 .=
" (title LIKE '%".
addslashes($qquery).
"%' OR id=".intval($q).") ";
$qp .= " (cat_name LIKE '%".addslashes($qquery)."%') ";
$addOR = true;
while ( list(,$val) = each($search_words) ) {
$val = ereg_replace("%","\\%",$val);
$val = ereg_replace("_","\\_",$val);
if ($addOR) {
$qp1 .= " AND ";
$qp .= " AND ";
}
$addOR = true;
$qp1 .=
" (title LIKE '%".
addslashes($val).
"%') ";
$qp .= "(cat_name LIKE '%".addslashes($qquery)."%') ";
}
// die($qp1);
// print $qp."<BR>";
$sql_count = "SELECT count(*) FROM PHPAUCTIONXL_auctions
WHERE ( $qp1 )
AND ( closed='0')
AND ( suspended='0')
AND private='n'
AND starts<=".$NOW."
ORDER BY buy_now";
$sql = "SELECT * FROM PHPAUCTIONXL_auctions
WHERE ( $qp1 )
AND ( closed='0')
AND ( suspended ='0')
AND private='n'
AND starts<=".$NOW."
ORDER BY buy_now";Re: Reverse htmlspecialchars or something
You might need to use str_replace or preg_replace then
Re: Reverse htmlspecialchars or something
oh! i did a small test and it worked!
But with English letters. I will test in with a Greek letter that it will be replaced by the decimal html code.
The problem is that when i write something in greek and save the file, it turns to decimal by its self!
I will test it now. Hope it works.
Please guide me if you have something to add.
Millions of thank you
But with English letters. I will test in with a Greek letter that it will be replaced by the decimal html code.
The problem is that when i write something in greek and save the file, it turns to decimal by its self!
I will test it now. Hope it works.
Please guide me if you have something to add.
Millions of thank you
Re: Reverse htmlspecialchars or something
It didn't work.
$qquery = ereg_replace("ι","ι ;",$query);
may because the page is saved as us-ascii endoding ?
$qquery = ereg_replace("ι","ι ;",$query);
may because the page is saved as us-ascii endoding ?
Re: Reverse htmlspecialchars or something
thank you my friend!