Search the Community
Showing results for tags 'xml encoding utf8'.
-
$doc = new DOMDocument(); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $doc->load("proba.xml"); $root = $doc->documentElement; $filmovi=mysql_query("SELECT * FROM film ORDER BY film_id DESC LIMIT 0,100"); while($pod=mysql_fetch_array($filmovi)) { $film = $doc->createElement('film'); $film = $root->appendChild($film); $link = $doc->createElement('link'); $link = $film->appendChild($link); $dodajlink = $doc->createTextNode('film-'.seoURL($pod['film_ime']."_".$pod['film_imesrpski']).'-'.$pod['film_id']); $dodajlink = $link->appendChild($dodajlink); $ime = $doc->createElement('ime'); $ime = $film->appendChild($ime); $dodajime = $doc->createTextNode(utf8_encode($pod['film_ime'].' '.$pod['film_imesrpski'].' '.$pod['film_imestrano'])); $dodajime = $ime->appendChild($dodajime); $doc->save("proba.xml"); } thet was proba.php proba.xml is: <?xml version="1.0" encoding="UTF-8"?> <pretraga> <film> <link>film-Rough_Magic_Opasna_magija-4657</link> <ime>Rough Magic Opasna magija </ime> </film> <film> <link>film-HouseSitter_uvarkua-4656</link> <ime>HouseSitter ?uvarku?a </ime> </film></pretraga> and livesearch.php $xmlDoc=new DOMDocument(); $xmlDoc->load("proba.xml"); $x=$xmlDoc->getElementsByTagName('film'); //get the q parameter from URL $q=$_GET["q"]; //lookup all links from the xml file if length of q>0 if (strlen($q)>0) { $hint=""; for($i=0; $i<($x->length); $i++) { $y=iconv('','UTF-8',$x->item($i)->getElementsByTagName('ime')); $z=$x->item($i)->getElementsByTagName('link'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (strpos($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="<a href='".$z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } else { $hint=$hint . "<br /><a href='".$z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint=="") { $response="Nema slicnih filmova"; } else { $response=$hint; } //output the response echo $response; livesearch and all work great except if i use non-english characters... i try with utf8_encoding but doesent work, i read a lot of diffrient things but i don't know how to use function like: iconv livesearch script When i try to add non-english charcter in xml file and when i use search i got this message: how can i fix this problem?