• Resolved stephenguillemin

    (@stephenguillemin)


    Hi,

    I have a problem to replace a number with a word. For example, when I write this :
    [str_replace( array( “2”, “30”, “22”,”MaisonVille”,”16″), array( “Maison”, “Maison de village”, “Corps de ferme”, “Maison de ville”, “Longère” ), {MAISON[1]/SS_TYPE[1]} )]
    For 2 it is OK with Maison
    But for 22 it is not OK because it displays MaisonMaison instead of Corps de ferme…
    Could you help me please?
    I am french so I am sorry if my english is not very good.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @stephenguillemin,

    But for 22 it is not OK because it displays MaisonMaison instead of Corps de ferme…

    You should switch to using strtr() in a custom function for this. Example:

    function my_replace_num( $data ) {
    	$map = array(
    		'2'           => 'Maison',
    		'30'          => 'Maison de village',
    		'22'          => 'Corps de ferme',
    		'MaisonVille' => 'Maison de ville',
    		'16'          => 'Longère'
    	);
    	
    	return strtr( $data, $map );
    }

    Usage:

    [my_replace_num({MAISON[1]/SS_TYPE[1]})]

    Plugin Author WP All Import

    (@wpallimport)

    Hi @stephenguillemin,

    I’m marking this as resolved since it’s been inactive for a while. You can follow up in this thread if you still have questions.

    Anyone else with questions, please open a new topic.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Replace word and number’ is closed to new replies.