WordPress.org

Forums

[resolved] Transforms a string of a custom field (4 posts)

  1. fcovicente
    Member
    Posted 6 years ago #

    Hi!

    I need to transform a text string that is produced by a custom field. The string is of type:

    http://domain.com/wp-content/uploads/2008/09/image.jpg

    And I need to transform it into something like:

    http://domain.com/wp-content/uploads/2008/09/image-225x150.jpg

    (only adds: "-225x150" to the string, almost at the end)

    I saved a lot of time with a solution. Thank you very much for your response.

    Best regards,

  2. fcovicente
    Member
    Posted 6 years ago #

    Any idea? any recommendations?

  3. yakuphan
    Member
    Posted 6 years ago #

    <?php
    $fileuri = 'http://domain.com/wp-content/uploads/2008/09/image.jpg';

    $extention = '.' . end(explode('.', $filename));
    $finalfileuri = substr($fileuri, strripos($fileuri, '.')) . '-225x150' . $extention;

    if it does'nt work, try this:

    $finalfileuri = substr($fileuri, strripos($fileuri, '.')-1) . '-225x150' . $extention;

    strripos= tr2.php.net/manual/en/function.strripos.php
    substr= tr2.php.net/manual/en/function.substr.php
    end= tr2.php.net/manual/en/function.end.php

  4. fcovicente
    Member
    Posted 6 years ago #

    Thank you very much, was very useful! :D

Topic Closed

This topic has been closed to new replies.

About this Topic