homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

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

 8:32 pm on Jun 9, 2011 (gmt 0)


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 Conceio" 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();

$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.'/';
$listdate = JFactory::getDate($row->listdate)->toFormat('%d/%m/%Y');

$nomedaimobiliaria='example.com - Portais Imobilirios de Florianpolis e SC';


Casas 18
Casas em condominios 19
Coberturas 20

case 17:
case 18:
case 19:
case 20:


/*$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]



 8:47 pm on Jun 9, 2011 (gmt 0)

Are we allowed to link to sourceforge? I saw this question and instantly thought: unitame


 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......


 2:30 am on Jun 10, 2011 (gmt 0)

use a function.

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:

$line.='<bairro>'. remove_accents($row->name_locality) .'</bairro>' . $crlf;

you may also try the iconv() function, using the //TRANSLIT flag


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 Conceio", shouldn't it stay that way? If you're only removing accents so your XML validates, use htmlentities() instead.



 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.


 2:48 am on Jun 10, 2011 (gmt 0)

I must ask: why are you removing accented characters? If your text is "Lagoa da Conceio", 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) ;-)


 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 ;)


 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]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved