solved | function > doesn't return data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

solved | function > doesn't return data

Post 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.
Last edited by $var on Tue Aug 25, 2009 9:10 am, edited 1 time in total.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: function > doesn't return data

Post by jackpf »

I don't see you echo() - ing or print() - ing anything.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Re: function > doesn't return data

Post 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?
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Re: function > doesn't return data

Post by $var »

echoing didn't work, but print(); did!

thank you for the tip!
Post Reply