WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $25.00 turns into .00, Is something removing my punctuation and numbers? (7 posts)

  1. Smaandar
    Member
    Posted 5 months ago #

    Hello all,

    I currently am working on writting a custom php script, that is being imported to a Word Press page through PHP via the 'insert-PHP' plugin. But that is not the intent of this post. Inside my script I have it print prices, such as '$25.00', through echo. Outside of Word Press it works wonderfully, and without the '$' symbol it continues to work. However, with the '$' symbol, while in Word Press, it removes everything from the '$' symbol to the next space, period, or non integral character.

    This means that '$25.00' Turns into '.00'.

    My question, is does Word Press have any built in filtering that is, well, filtering this out? If so, is it possible to override this filter and not remove these characters?

    Thanks in advance,
    ~Smaandar

  2. Smaandar
    Member
    Posted 5 months ago #

    A bit of a good example.

    [insert_php]
    
         echo "$25.00";
    
    [/insert_php]

    prints ".00"

    but

    [insert_php]
    
         echo "25.00";
    
    [/insert_php]

    Prints 25.00

  3. Smaandar
    Member
    Posted 5 months ago #

    The only fix I've found is to make a custom page template for the page in question in Word Press, and put my php code into there.

  4. Chris Dillon
    Member
    Posted 5 months ago #

    The dollar sign indicates a variable declaration in PHP. Try the HTML character code $ instead.

    "$25.00"

    Reference: http://www.ascii.cl/htmlcodes.htm

  5. Smaandar
    Member
    Posted 5 months ago #

    The dollar sign indicates a variable declaration in PHP. Try the HTML character code $ instead.

    Yes I know it's a variable declaration. However, a line such as

    echo("This cost $19.95");

    Should not declare a variable, it should simply be printing "This cost $19.95" without removing half of the value.

    This works outside of WordPress, and as a custom page template. So I think it's quite possible that it is something in the insert-php plugin that I was using.

    Also, although it is resolved, I would like to note that I cannot use the html character code because it lists titles based on file names. If the file name has $30 in it, it will break the entire title.

    So for now, the solution is to create a custom template file for the page, and include the script through the template php, and NOT from within WordPress through a third party plugin.

  6. Chris Dillon
    Member
    Posted 5 months ago #

    For what it's worth, your solution is the much better way to go.

    You're right about echo but that plugin uses eval() without escaping the text first so the $25 is being interpreted as a variable. WordPress is not stripping anything before it gets eval-ed.

    For safe titles, try sanitize:

    echo sanitize_title( $title );
  7. Smaandar
    Member
    Posted 5 months ago #

    Oh, I had no idea it was using eval(), that makes a lot more sense now.

    Thanks for your help.

Reply

You must log in to post.

About this Topic