Cannot get rid of the character '. It produces a diamond with question marks that code. Already tried everything.

if ( $terms ) { $i = 2; printf( '<div class="%s"> <h2 class="text-center">Select one of the functional areas</h2> <ul class="clearfix">', esc_attr( $class ) ); printf( '<li class="'.$activet.'" ><a href="%s">All categories</a><div class="description">All categories on one page</div></li>', esc_url( site_url() )); foreach ( $terms as $term ) { $active =''; // The $term is an object, so we don't need to specify the $taxonomy. $term_link = get_term_link( $term ); $term_name = esc_html( $term->name ); $clean = preg_replace("/[^\w]/", "", $term_name); $name = "/\b".$clean."\b/i"; if (preg_match($name,$link) == true && preg_match($name,$url) == true) { $active = 'active-taxonomy'; } else { $active =''; } // If there was an error, continue to the next term. if ( is_wp_error( $term_link ) ) { continue; } printf( '<li class="'.esc_html( $term->name ).' '.$active.'" ><a href="%s">%s</a><div class="description">%s</div></li>', esc_url( $term_link ), esc_html( $term->name ),esc_html( $term->description ) ); if (($i % 3) === 0) { echo '<li class="clear">&nbsp;</li>'; } $i++; } print( '</ul></div>' ); } 

If you do this:

  if ( $terms ) { $i = 2; printf( '<div class="%s"> <h2 class="text-center">Select one of the functional areas</h2> <ul class="clearfix">', esc_attr( $class ) ); printf( '<li class="'.$activet.'" ><a href="%s">All categories</a><div class="description">All categories on one page</div></li>', esc_url( site_url() )); foreach ( $terms as $term ) { $active =''; // The $term is an object, so we don't need to specify the $taxonomy. $term_link = get_term_link( $term ); $term_name = $term->name; $clean = preg_replace("/[^\w]/", "", $term_name); $name = "/\b".$clean."\b/i"; $low = strtolower($name); $link = strtolower($term_link); if (preg_match($name,$link) == true && preg_match($name,$url) == true) { $active = ' active-taxonomy'; } else { $active =''; } // If there was an error, continue to the next term. if ( is_wp_error( $term_link ) ) { continue; } printf( '<li class="'.$low.$active.'" ><a href="%s">%s</a><div class="description">%s</div></li>', esc_url( $term_link ), esc_html( $term->name ),esc_html( $term->description ) ); if (($i % 3) === 0) { echo '<li class="clear">&nbsp;</li>'; } $i++; } print( '</ul></div>' ); } 

That issues - hildrensroom. I generally can not understand in this case. I will be glad to any help.

    2 answers 2

    Maybe because you are replacing in another variable? try this:

      $h = "Man's horse"; $replace = preg_replace("/[^\w]/", "", $h); var_dump($replace); 
    • Yes, it's a typo. Not promoted with var_dump: string (17) "Сhildren039sroom". The problem is in the regular expression itself. I can not understand how to specify this particular symbol so that it is not on the output. - Andrei Sukharev
    • $ h = preg_replace ("/ [^ \ w] /", '', $ term_name); $ clean = preg_replace ("/ [^ a-zA-Z] /", '', $ h); - Andrei Sukharev
    • @Andrei Sukharev, the code from the response will issue a string(9) "Manshorse" . You got rid of both single quotes and spaces. - Visman
    • that's right I guess I have a conflict of WordPress features with php. Maybe look at the code above - I gave the options and results. - Andrei Sukharev
    • one
      @AndreiSukharev so try such a regular expression [^ \ w \ s] - remove everything except letters and spaces - Andrii Kulyk

    String replicate not

    str_replace("'","",$h);