• Resolved apofisgold

    (@apofisgold)


    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter apofisgold

    (@apofisgold)

    I would like to clarify that in xml files there are other values in nodes that need to be changed to other text values, and there are also values in nodes that do not need to be changed.

    An example of what needs to be changed:

    function house_type_propertynew($type){
    $type = str_replace('Parking Space', 'garage', $type);
    $type = str_replace('Apartamento', 'Apartment', $type);
    $type = str_replace('Ground Floor', 'Apartment', $type);
    $type = str_replace('Flat', 'Apartment', $type);
    $type = str_replace('detached house', 'SemiDetached', $type);
    $type = str_replace('Semi', 'SemiDetached', $type);
    $type = str_replace('Detached Villa', 'SemiDetached', $type);
    $type = str_replace('Semi-detached', 'SemiDetached', $type);
    $type = str_replace('Semi-Detached House', 'SemiDetached', $type);
    $type = str_replace('semi-detached-villa', 'SemiDetached', $type);
    $type = str_replace('Semi - Detached Villa', 'SemiDetached', $type);
    $type = str_replace('Terraced house', 'Town House', $type);
    $type = str_replace('Townhouse', 'Town House', $type);
    $type = str_replace('terraced house', 'Town House', $type);
    $type = str_replace('House – Townhouse', 'Town House', $type);
    $type = str_replace('Quad Bungalow', 'Quad', $type);
    $type = str_replace('Quad House', 'Quad', $type);
    $type = str_replace('Quadplex', 'Quad', $type);
    $type = str_replace('Quad Villa', 'Quad', $type);
    $type = str_replace('Chalet', 'Villa', $type);
    $type = str_replace('Chalets Pareados', 'Villa', $type);
    $type = str_replace('Village house', 'Villa', $type);
    $type = str_replace('Village House', 'Villa', $type);
    $type = str_replace('Villa with annex', 'Villa', $type);
    $type = str_replace('Villas Pareados', 'Villa', $type);
    $type = str_replace('Finca / Country Property', 'Country Estate', $type);
    $type = str_replace('finca', 'Country Estate', $type);
    $type = str_replace('Country Property/Finca', 'Country Estate', $type);
    $type = str_replace('Country Property', 'Country Estate', $type);
    $type = str_replace('Country House', 'Country Estate', $type);
    $type = str_replace('Plot of Land', 'Plot', $type);
    $type = str_replace('Building Plot', 'Plot', $type);
    $type = str_replace('land', 'Plot', $type);
    $type = str_replace('Land', 'Plot', $type);
    $type = str_replace('Restoration Project', 'Plot', $type);
    $type = str_replace('Duplex apartment', 'Duplex', $type);
    $type = str_replace('Bar', 'Restaurants and Bars', $type);
    $type = str_replace('Bar/Restaurant', 'Restaurants and Bars', $type);
    $type = str_replace('Commercial Unit', 'commercial', $type);
    $type = str_replace('Commercial Building', 'commercial', $type);
    $type = str_replace('Locales Comerciales', 'commercial', $type);
    $type = str_replace('Business premises', 'commercial', $type);
    $type = str_replace('Bungalows Planta Baja', 'Bungalow', $type);
    $type = str_replace('Bungalows Planta Alta', 'Bungalow', $type);
    return $type;}
    
    Plugin Author WP All Import

    (@wpallimport)

    Hi @apofisgold,

    Custom PHP functions are not supported in our free plugins, and we can only help with our free plugins in this forum.

    If you’re using the pro version, please contact us with this question here: https://www.wpallimport.com/support/. Note that we will not be able to write or modify the code as part of our support, but we can check to make sure the function is being used correctly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘I need to change the text value in the nodes to SemiDetached’ is closed to new replies.