Real-Time Find and Replace
[resolved] Issue with html chars (5 posts)

  1. acub
    Posted 2 years ago #

    I really appreciate the simplicity and effectiveness of your plugin.

    I have a small problem replacing html chars, because every time I save they get converted in whateer they look on the page. For example,

    &#8211 ;

    gets replaced with a dash (I've added a space there as WP forum also turns it into a dash, even if i write it "&amp ;#8211;" - no spaces :).

    So, every time I want to add a new replace, I need to replace the html chars in my previous replaces or they won't work.
    Is there anything to be done about this? Maybe add a hook to the replaces array and let me add an extra array of replaces in functions.php through a filter?

    Thank you for looking into this.


  2. acub
    Posted 2 years ago #

    I have made myself a temporary solution. In your plugin file, I have added this code to far_ob_call function, after the is_array check:

    if (function_exists('far_get_extra')) {
    	$far_extra_replaces = far_get_extra();
    	if (is_array($far_extra_replaces))
    		foreach ($far_extra_replaces as $extra_find => $extra_replace) {
    			$farsettings['farfind'][] = $extra_find;
    			$farsettings['farreplace'][] = $extra_replace;

    And in functions.php I declared my far_get_extra function which returns the array of replacements without the worry that html chars will get converted into their meanings by WP. Not sure if the $find => $replace type of array for extra replaces will work in all cases (maybe some chars aren't allowed in keys), but it does in mine.

  3. acub
    Posted 2 years ago #

    I found the solution for this.
    In the end, it turns out WP has a function that prevents textarea from replacing html entities into their result: http://codex.wordpress.org/Function_Reference/esc_textarea

    Therefore, both $find and $replace vars need to be wrapped in esc_textarea() on line 115 of $real-time-find-and-replace.php, resulting in:

    echo "<p id='row$i'><label for='farfind$i'>Find:&nbsp;</label><textarea rows='3' cols='30' name='farfind[$i]' id='farfind$i'>".esc_textarea( $find )."</textarea>&nbsp;&nbsp;<label for='farregex$i'>RegEx?:&nbsp;</label><input type='checkbox' name='farregex[$i]' id='farregex$i' $regex />&nbsp;&nbsp;<label for='farreplace$i'>Replace:&nbsp;</label><textarea rows='3' cols='30' name='farreplace[$i]' id='farreplace$i'>".esc_textarea( $replace )."</textarea>&nbsp;&nbsp&nbsp;<a href='#' onClick='removeFormField(\"#row$i\"); return false;'>Remove</a></p>\n";

    Please include this in the next release, if it's not too much trouble.

    Thank you!

  4. Marios Alexandrou
    Plugin Author

    Posted 2 years ago #

    Thanks for the code to fix this issue. The latest version includes it.

  5. acub
    Posted 2 years ago #

    Excellent. Thank you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Real-Time Find and Replace
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.