PHP Problem

Discussion in 'PHP' started by hassanahmad2, Jun 3, 2009.

Thread Status:
Not open for further replies.
  1. #1
    Hello everyone,

    I have a quite complicated problem. I am using template files to edit a script. It has symbols with special meaning like {$clientsarea.firstname} etc
    I need to put these in php coding. But they are processed after the php tags.
    Currently i am using something like the following, but its not working.

    
    <?php
    
    $link = mysql_connect($server, $user, $pass);
    if(!mysql_select_db($database)) die(mysql_error());
    
    $id = '{$clientsdetails.id}';
    
    ?>
    
    Code (markup):
    I want the sybmol {$clientsdetails.id} to be processed by the template engine and then that info is stored in $id.
    Is there any way of doing this?? I need this fixed quick.

    Thanks,
    Hassan
     
    hassanahmad2, Jun 3, 2009 IP
  2. sniurkst

    sniurkst Peon

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why can't you just use the variables before the template processing? Wouldn't that be more logical?
     
    sniurkst, Jun 3, 2009 IP
  3. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #3
    As I understand it, the value {$clientsdetails.id} isn't replaced with the actual value (say, "foo"), until after HTML is printed?

    I'm thinking the best way to do it is to use PHP to save the actual value of {$clientsdetails.id} in a file named "clientsdetails.txt" or whatever, then use a server side include to run another PHP file. I think you can include php with ssi..?
     
    tguillea, Jun 3, 2009 IP
    hassanahmad2 likes this.
  4. jnugroho73

    jnugroho73 Peon

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try to use ob_start() function like this:
    
    <?php
    function callback($buffer)
    {
    if(preg_match('/<id>(.*?)<\/id>/si',$buffer,$regs)){
    $id=$regs[1]; // here you get the variable that you can store anywhere
    }
    return $buffer;
    }
    
    ?>
    <id>{$clientsdetails.id}</id>
    Code (markup):
    Good luck:cool:
     
    jnugroho73, Jun 3, 2009 IP
  5. jnugroho73

    jnugroho73 Peon

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I am sorry that I forgot to place ob_start function in the code.
     
    jnugroho73, Jun 3, 2009 IP
  6. hassanahmad2

    hassanahmad2 Active Member

    Messages:
    243
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #6
    I think buffering the output is what i needed. I will try it soon.
    Thanks very much to all for helping. Rep+ given.
     
    hassanahmad2, Jun 3, 2009 IP
Thread Status:
Not open for further replies.