Page 1 of 1

solved | function > doesn't return data

Posted: Tue Aug 25, 2009 8:23 am
by $var
Hello,
I have a function that, when run completely, doesn't return it's data to the page from which it is called. The tricky part is, that if I put a die(); in at the end of the function, it is getting through it completely and spitting out the last value.

Code: Select all

function getPath($url) {
 
    $parsed = parse_url($url);
    $trimmed = ltrim($parsed['path'], '/');
    $parts = explode('/', $trimmed);
    
    foreach($parts as $part){
         if (!is_numeric($part)){
             $combined_parts[] = $part;
         } elseif(is_numeric($part)) {
             break;
         }
    }
    
     $string = implode(':', $combined_parts);
     return $string;
}
so... echo $string = ... outputs in the source when the function has a die.

this is on the page calling the function:

Code: Select all

 
  <?php
    # DFP Omniture Tagging
    getDOTPath($_server['REQUEST_URI']."/hockey/nhl/maple_leafs/");
    ?>
 
any ideas why it won't return to the template?


thank you very much.

Re: function > doesn't return data

Posted: Tue Aug 25, 2009 8:44 am
by jackpf
I don't see you echo() - ing or print() - ing anything.

Re: function > doesn't return data

Posted: Tue Aug 25, 2009 9:03 am
by $var
i should be doing this in the template right?

Code: Select all

<?php
    # DFP Omniture Tagging
    getDOTPath($_server['REQUEST_URI']."/hockey/nhl/maple_leafs/134513452/this_is_the_story_headline");
    echo $string;
    ?>
 
I had that, and it wasn't doing anything. ?

From my understanding, in the function you use return $var; to ... finalize the function, and then echo $var; in the template?

Re: function > doesn't return data

Posted: Tue Aug 25, 2009 9:10 am
by $var
echoing didn't work, but print(); did!

thank you for the tip!