WordPress.org

Ready to get started?Download WordPress

Forums

Replacing x between two numbers in the post title or the content (3 posts)

  1. bigneno
    Member
    Posted 3 years ago #

    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 55x66, 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.

  2. terriann
    Member
    Posted 3 years ago #

    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()

  3. bigneno
    Member
    Posted 3 years ago #

    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 9x9 into 9×9 ?

Topic Closed

This topic has been closed to new replies.

About this Topic