Support » Plugins » Hacks » Replacing x between two numbers in the post title or the content

  • Hi, I’ve just noticed that WP replaces letter X between two numbers with a different × (ascii code, smaller, vertically-centered).
    For example: I have a post title containing 55×66, in a post view it’s ok to read, but when I use post_title() in $wpdb->prepare() to store some data and then send it with wp_mail function, the x is replaced with ( & # 215 ; without spaces ) which is really annoying.
    I tried to add_filter and str_replace it to turn this of, but no luck. Any ideas? Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • That’s because you’re not using an x but instead a multiplication symbol fileformat.info/info/unicode/char/d7/index.htm

    You have two possible solutions:

    1. Don’t use the × symbol and instead use a letter x
    2. Use the PHP function html_entity_decode() to decode the hmtl entity.
    – When WordPress turns the multiply symbol to the & #215; it’s encoding the symbol into an HTML entity, a very common practice when storing data in a database.
    – Since you’ll want to process the post_title you’ll need to use the WordPress method to return it not print it to the screen. you mentioned post_title() in the question but that’s not a WordPress function so I cannot direct you to the right function to return rather than print, but they’re usually get_post_title() rather than post_title()

    Thank you for your reply.
    This happens when I use a typical letter x between numbers, not the × symbol. A normal x is somehow converted to × if x is inserted between two numbers without spaces. I checked it in my database and there are 100% simple x-s.
    Of course I meant “get_the_title”.
    So, when I use $title = get_the_title(999) and then use $title in sql prepared query there’s & #215;.
    Is there any other function to get the title which doesn’t convert simple 9×9 into 9×9 ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Replacing x between two numbers in the post title or the content’ is closed to new replies.