How to trim a rendered item before and after specific symbols I've created a field where I store the URL to an image. I need to display the filename of the image without the part before the slash and without the file extension.


  http://some.url.com/folder/this/and/that/361.jpg


should be displayed as 361


  http://some.url.com/url/folder/this/and/that/1021.jpg


should be displayed as 1021

I know that this can be handled field--field-name-of-url.tpl.php file but I wasn't able to apply the solutions I've found correctly.

I tried the regex and explode method but I don't know how to insert it into the code below.

Thanks for any help.

&lt;?php foreach ($items as $delta =&gt; $item) : ?&gt;
    &lt;?php print render($item); ?&gt;
&lt;?php endforeach; ?&gt;
A tip from a friend got it working. Here the solution.

&lt;?php foreach ($items as $delta =&gt; $item) : ?&gt;
    &lt;?php 
     $file_extension = substr(render($item) , strrpos(render($item) , '.') +1);
     print basename(render($item), '.'.$file_extension);
    ?&gt;
     &lt;/p&gt;
&lt;?php endforeach; ?&gt;