Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-10-2012, 02:04 PM   PM User | #1
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
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..
Trki is offline   Reply With Quote
Old 12-10-2012, 03:06 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 12-10-2012, 03:34 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,496
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 12-12-2012, 11:52 AM   PM User | #4
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
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.
Trki is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:35 AM.


Advertisement
Log in to turn off these ads.