I’m importing from different xml files.example structure:
1)
1-sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
<kyero>
<feed_version>3</feed_version>
</kyero>
<property>
<type><![CDATA[Detached Villa]]></type>
<town>Ciudad Quesada</town>
</property>
<property>
<type><![CDATA[Semi Detached Villa]]></type>
<town>Benijofar</town>
</property>
</root>
2)
2-sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
<kyero>
<feed_version>3</feed_version>
</kyero>
<property>
<type>semi-detached-villa</type>
<town>Villena</town>
</property>
<property>
<type>Semi</type>
<town>Elda</town>
</property>
</root>
3)
3-sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
<kyero>
<feed_version>3</feed_version>
</kyero>
<property>
<type>Semi-Detached House</type>
<town>Villena</town>
</property>
<property>
<type>Semi - Detached Villa</type>
<town>Elda</town>
</property>
</root>
I need to change the text value in the nodes to SemiDetached.
I’m using the str_replace function.
function house_type_propertynew($type){
$type = str_replace('Semi Detached Villa', 'SemiDetached', $type);
$type = str_replace('Detached Villa', 'SemiDetached', $type);
$type = str_replace('Semi-Detached House', 'SemiDetached', $type);
$type = str_replace('Semi', 'SemiDetached', $type);
$type = str_replace('Semi-Detached House', 'SemiDetached', $type);
$type = str_replace('Semi - Detached Villa', 'SemiDetached', $type);
return $type;}
The result is several values instead of “SemiDetached”:
SemiDetached – SemiDetached
SemiDetachedDetached
SemiDetached-detached
That is, the text is duplicated, mixed up, folded differently but does not give the desired “SemiDetached” result!
What am I doing wrong?