Defining/parsing/php/tpl issue

Discussion in 'PHP' started by Mr.Bill, Dec 21, 2008.

  1. #1
    I know I messed this up badly and would like to know how to fix this


    
    // Total random Start
    
    function randomQuote ($file) {
       $f = file($file);
       $k = array_rand($f);
       $q = $f[$k];
    }
    
    $proxiesrandom = randomQuote("random_link.txt");
    
    $sRow = $proxiesrandom;
    $random = $sRow['randomQuote'];
    
    	$tpl->parse(
    		'random',
    		array(
    			'random' => $q,
    			)
    		);
    // Total random End
    
    PHP:
    I have a file with

    <?
    
    function randomQuote ($file) {
       $f = file($file);
       $k = array_rand($f);
       $q = $f[$k];
       echo $q;
    }
    
    ?> 
    PHP:
    A text file with random quotes
    in a normal situation I would be able to use this line
    <? randomQuote("random_link.txt"); ?>
    PHP:
    but since my design uses tpl I cant

    and I need to be able to run this in a tpl file but cant figure out how to add the above into my current design using the parse format from above.
     
    Mr.Bill, Dec 21, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    why not doing it with javascript instead, you can add all lines to a javascript and the javascript returns every page a random line! ;) it's just quick tought!
     
    EricBruggema, Dec 28, 2008 IP
  3. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #3
    <?php
    
    include 'whatever_file.tpl'; // This will execute it as a PHP file.
    PHP:
     
    Danltn, Dec 28, 2008 IP
  4. hackfanatic

    hackfanatic Peon

    Messages:
    29
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    change your function randomQuote ln 4 "echo $q;" to "return $q;"
     
    hackfanatic, Dec 28, 2008 IP
  5. Mr.Bill

    Mr.Bill Well-Known Member

    Messages:
    2,818
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Sorry for now closing this earlier. I had hired someone to resolve this.

    Thread Closed
     
    Mr.Bill, Dec 28, 2008 IP