• Resolved paundrew

    (@paundrew)


    I am trying to use the str_replace command to replace part of an automatically generated URL. The original URL is placed in custom value (‘url’). I need to replace occurrences of “rtex” with “190” in the url itself. The code currently reads:

    <?php $url = get_post_custom_values(“url”);
    echo str_replace(“rtex”, “190”, $url);?>

    It should be fairly simple, but I am getting a return of:

    “Array”

    I’m not terribly experienced with PHP, and any help much appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • get_post_custom_values returns an array of all values stored against the key – in your case url. Even if there’s only 1 value, it will still return an array. Try something like:

    echo str_replace("rtex", "190", $url[0]);?>

    Thread Starter paundrew

    (@paundrew)

    Great, works perfectly. I’m unfamiliar with php and little things like this can be tricky to work with. Thanks very much esmi.

    Paul

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘changing url value with str_replace(), retuns “Array”’ is closed to new replies.