How to replace a string in a URL field when outputting it in a template file I created a new field for URL. What would the best way to replace certain strings in the URL when outputting the field into the field--field_url.tpl.php file be?

For example, in http://example.com/master/m/ I need to remove the "http://" part, and replace master with slave.

It is a single field; there will be no foreach() loops.

==== edit after using preprocess ===
i got a undefined index: field_url

with the devel i get this

field_url
   und
     0
       value


i put in the preprocess

$link = $variables['field_url'][LANGUAGE_NONE][0]['value'];

$link = str_replace('http://', "", $link);

$link = str_replace('master', 'slave', $link);

$variables['link'] = $link;


is this right?

====== entire hook =======

function lessxless_preprocess_field(&amp;$variables)
{ 
    $link = $variables['field_url'][LANGUAGE_NONE][0]['value']; // grab value

    $link = str_replace('https://', "", $link); // trim http://

    $link = str_replace('master', 'slave', $link);

    $variables['link'] = $link;
}

sites/all/themes/lessxless/template.php
You probably want a preprocess function in your template.php for this. In your case, hook_preprocess_field() will be easiest to work with - for an example of how this is implemented, check out the API documentation for template_preprocess_field(). 

Remember, $variables is passed into preprocess hooks by reference. From within your hook_preprocess_field(), instead of modifying the field data directly (in case you need it elsewhere), you could do something like this after checking that you're operating on the right field:

/* devel's dpr() is handy for seeing where in the $variables array it lives if you 
   don't have a debugger handy. If you see 'und', that's the value for the LANGUAGE_NONE
   constant. It's considered best practice to use the constant instead. */
$slave_link = $variables['field_url'][LANGUAGE_NONE][0]['value'];  
$slave_link = str_replace("http://", '', $slave_link); // Trim http://
$slave_link = str_replace("master", "slave", $slave_link); // s/master/slave
$variables['slave_link'] = $slave_link;  /* You can now access this variable from your
                                            field--field_url.tpl.php as $slave_link */


You may also need to clear your cache after making these changes.