| replace character with accent with chatacters with NO accents xml replace characters with accent |
imofloripa

msg:4324267 | 8:32 pm on Jun 9, 2011 (gmt 0) | Hello. I am working for a company that asks me to learn to do things I dont know how to do. I have been searching a lot in many forums for a function to insert in a PHP file that creates an XML output. I need to replace accented characters with characters with NO accents: EX: "Lagoa da Conceição" needs to be replaced to "Lagoa da Conceicao" and so on. Can anybody PLEASE PLEASE PLEASE help me to accomplish this task? This is the field where i need the characters to be replaces: $line.='<bairro>'.$row->name_locality.'</bairro>' . $crlf; below i will paste the code that generates the XML:
function vivareal() {
$db=& JFactory::getDBO();
$query = ' SELECT p.*,c.name as name_category,t.name as name_type,cy.name as name_country,s.name as name_state,l.name as name_locality,pf.name as name_profile, ' . ' CASE WHEN CHAR_LENGTH(p.alias) THEN CONCAT_WS(":", p.id, p.alias) ELSE p.id END as Pslug,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as Cslug,' . ' CASE WHEN CHAR_LENGTH(cy.alias) THEN CONCAT_WS(":", cy.id, cy.alias) ELSE cy.id END as CYslug,' . ' CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(":", s.id, s.alias) ELSE s.id END as Sslug,' . ' CASE WHEN CHAR_LENGTH(l.alias) THEN CONCAT_WS(":", l.id, l.alias) ELSE l.id END as Lslug, ' . ' CASE WHEN CHAR_LENGTH(t.alias) THEN CONCAT_WS(":", t.id, t.alias) ELSE t.id END as Tslug ' . ' FROM #__properties_products AS p ' . ' LEFT JOIN #__properties_country AS cy ON cy.id = p.cyid ' . ' LEFT JOIN #__properties_state AS s ON s.id = p.sid ' . ' LEFT JOIN #__properties_locality AS l ON l.id = p.lid ' . ' LEFT JOIN #__properties_profiles AS pf ON pf.mid = p.agent_id ' . ' LEFT JOIN #__properties_category AS c ON c.id = p.cid ' . ' LEFT JOIN #__properties_type AS t ON t.id = p.type ' . ' WHERE p.published = 1 ' . ' AND p.cid IN(17,18,19,20) ' .' ORDER BY p.id DESC ' ;
$db->setQuery( $query ); $products = $db->loadObjectList();
$crlf="\n"; $line = '<?xml version="1.0" encoding="utf-8"?>' . $crlf; $line .= '<imoveis>'. $crlf; foreach ( $products as $row ) { $url = substr(JURI::base(), 0, -1); $link = $url.LinkHelper::getLink('properties','showproperty','',$row->CYslug,$row->Sslug,$row->Lslug,$row->Cslug,$row->Tslug,$row->Pslug);
$title = $this->escape( $row->name ); //$category = JText::_('TROVIT_CAT_'.$row->name_category); //$category = 'For Sale'; $price = number_format($row->price, 2,",","."); $imageBaseUrl = JURI::root().'images/properties/images/'; $imageUrl = $imageBaseUrl.$row->id.'/'; $images=$this->Images($row->id); $listdate = JFactory::getDate($row->listdate)->toFormat('%d/%m/%Y');
$nomedaimobiliaria='example.com - Portais Imobiliários de Florianópolis e SC'; $urldaimobiliaria=JURI::root();
$tipo='RESIDENCIAL';
/* Apartamentos17 Casas 18 Casas em condominios 19 Coberturas 20 */
switch($row->cid) { case 17: $subtipo='APARTAMENTO'; break; case 18: $subtipo='CASA'; break; case 19: $subtipo='CASA'; break; case 20: $subtipo='COBERTURA'; break;
}
/*$line.='<>'.$row->.'</>' . $crlf;*/ $line.='<imovel>'. $crlf; $line.='<statusdoimovel>a venda</statusdoimovel>' . $crlf; $line.='<localizacao>' . $crlf; $line.='<endereco>'.$row->name_locality.'</endereco>' . $crlf; $line.='<bairro>'.$row->name_locality.'</bairro>' . $crlf; $line.='<cidade>'.$row->name_state.'</cidade>' . $crlf;
[edited by: httpwebwitch at 2:20 am (utc) on Jun 10, 2011]
|
lucy24

msg:4324277 | 8:47 pm on Jun 9, 2011 (gmt 0) | Are we allowed to link to sourceforge? I saw this question and instantly thought: unitame
|
imofloripa

msg:4324285 | 9:14 pm on Jun 9, 2011 (gmt 0) | another thing i forgot to mention is that i need the xml output without accents only for the string: $line.='<bairro>'.$row->name_locality.'</bairro>' . $crlf; and not for the other strings.... please someone helps me, please, i need to keep pthis job......... my family needs it......
|
httpwebwitch

msg:4324386 | 2:30 am on Jun 10, 2011 (gmt 0) | use a function. <?php function remove_accents($str){ $search = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u"); $replace = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u"); return str_replace($search, $replace, $str); } ?> then wherever you need to remove accents, do it thusly: <?php $line.='<bairro>'. remove_accents($row->name_locality) .'</bairro>' . $crlf; ?> you may also try the iconv() function, using the //TRANSLIT flag [php.net...] <?php function remove_accents($str){ return iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str); } ?> I must ask: why are you removing accented characters? If your text is "Lagoa da Conceição", shouldn't it stay that way? If you're only removing accents so your XML validates, use htmlentities() instead. [ca2.php.net...]
|
lucy24

msg:4324390 | 2:45 am on Jun 10, 2011 (gmt 0) | Awk! Everyone does this and it's wrong. Unless your source is in Turkish-- which is not statistically as likely as the alternative-- å should go to aa (really). And ø is equivalent to ö and should therefore go to oe. I hope the strings in question are to be used in addresses, which have to be plain ASCII. Or anchors-- which technically don't, but keeping non-ASCII characters is just asking for trouble. In most circumstances, changing to entities would be more appropriate. Edit: ###. I don't know what happened there. It looked right in Preview. Anyway, a-ring goes to aa while o-slash goes to oe.
|
Leosghost

msg:4324391 | 2:48 am on Jun 10, 2011 (gmt 0) | | I must ask: why are you removing accented characters? If your text is "Lagoa da Conceição", shouldn't it stay that way? If you're only removing accents so your XML validates, use htmlentities() instead. |
| I'll second that "ask", and the suggestion(s) , 'specially the last one...htmlentities | I don't know what happened there |
| Texan BB code(r) ;-)
|
lucy24

msg:4324441 | 5:58 am on Jun 10, 2011 (gmt 0) | | I don't know what happened there |
| Texan BB code(r) ;-) |
| But Seriously! This Forums page doesn't :: cough, cough :: ahem :: specify a charset. Setting it manually to ISO-Latin-1 turned the characters back from Cyrillic (?!) into accented Roman letters. Which is not entirely OT ;)
|
imofloripa

msg:4324640 | 4:15 pm on Jun 10, 2011 (gmt 0) | Hi httpwebbitch! thanks a lot for the code, i am trying to use it. To reply to your answer, i need the localities without accents because i am trying to send 400 properties to be published via XML in the <<bleeeeeep ~ mod>> portal, and they need the localities without accents for the integration. I really dont understand why. anyway i am trying your code, will let you know asap. Thanks to everybody, really very appreciated. [edited by: httpwebwitch at 1:04 am (utc) on Jun 11, 2011] [edit reason] removed specifics [/edit]
|
|
|