Support » Plugin: Import any XML or CSV File to WordPress » Spintax function not working

  • Resolved nicoco35

    (@nicoco35)


    hello

    I tried the spintax function you posted here: https://paste.ee/p/GluOL

    and pasted it in the function editor as: (see below)

    but it’s not spinning my spintax when I preview ! what should I do ?

    <?php
    function my_spintax( $string ) {
    $data = preg_match_all( “/(?=\{).*?(?=\})./”, $string, $match );

    if ( !empty( $match ) ) {
    foreach ( $match as $key => $value ) {
    if ( !empty( $value ) ) {
    foreach ( $value as $values ) {
    $v = explode( “|”, $values );
    $i = array_rand( $v );
    $string = str_replace( $values, str_replace( array( “{“, “}” ), “”, $v[ $i ] ), $string );
    }
    }
    }
    }
    return $string;
    }
    ?>

Viewing 2 replies - 16 through 17 (of 17 total)
  • Hi Nicoco35!

    Can you please share the php code for the nested spintax?

    Hi @nicoco35

    Can you please share the php code for the nested spintax?
    does not seem to work:

    <?php
    function my_spintax( $string ) {
    	$data = preg_match_all( "/\{(((?>[^\{\}]+)|(?R))*)\}/x", $string, $match );
    	
    	if ( !empty( $match ) ) {
    		foreach ( $match as $key => $value ) {
    			if ( !empty( $value ) ) {
    				foreach ( $value as $values ) {
    					$v = explode( "|", $values );
    					$i = array_rand( $v );
    					$string = str_replace( $values, str_replace( array( "{", "}" ), "", $v[ $i ] ), $string );
    				}
    			}
    		}
    	}
    	return $string;
    }
    ?>
Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Spintax function not working’ is closed to new replies.