Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: buffer php

  1. #1
    Regular Coder
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    111
    Thanks
    9
    Thanked 0 Times in 0 Posts

    buffer php

    Hi i am in situation when i want to have different descriptions for certain pages.... and i need this meta description set with data from the middle part of website so ...

    PHP Code:

    <?php ob_start();?>
     <html>
     <head>
     <meta name="description" content="replace_this"/> 
     </head>
     <body>
                <?php $new_description='new_desc';?>
     </body>
    </html><?php ob_end_flush(); ?>
    and... i was thinking about something like str_replace method or ... something like that...
    What do you say and if somebody know how to do it i would appreciate code example :P thx
    Last edited by Trki; 12-12-2012 at 11:53 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Buffer contents can be extracted using the ob_get_contents method. You can then use replace_this as the search criteria.
    PHP Code:
    $contents ob_get_contents();
    ob_end_clean();
    $contents str_replace('replace_this''New Description'$contents);
    print 
    $contents
    Although I'd suggest it would be easier to simply use a variable to represent the description instead.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by Trki View Post
    i need this meta description set with data from the middle part of website so ...
    To be honest, you would be better off running your php logic FIRST and then putting the generated variables into your template at the end and printing it out.

    It will save you a lot of hassle in the long run
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    Regular Coder
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    111
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thx a lot i was trying this myself but it still felt somewhere... i think the problem was that i didnt used ob_end_clean but i used of_flush or something like that.

    Thx a lot guys.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •