Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 15th, 2004, 01:04 PM
Authorized User
 
Join Date: Nov 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jefferis Send a message via AIM to jefferis Send a message via MSN to jefferis
Default Get meta tag from current page? PHP 4.x

I'm trying to update a client's static pages which have item descriptions in the 'description' meta tag content. I want to print the descriptions under the image on the existing page, which I am converting to php.

 I've checked out some of the get_meta_tag functions but am finding that they seem to require searching another page via a path. I'm trying to get the data on this current page. I'm wondering if the command structure will allow this and if there is an example that someone could point me to. It seems that since the info is given by the server as the page is created, any php function would kick in too late to display?

~~~~~~~~~~~~~
 http://www.petersonsales.net
__________________
~~~~~~~~~~~~~
 http://www.petersonsales.net
 
Old September 15th, 2004, 05:04 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Without extracting the meta data and putting it in a database and then dynamically including it where ever you want, one possible hack is to access the DOM at the server level. PHP provides an extension for doing this, http://www.php.net/dom.

In order to use this extension on the current page as opposed to opening and accessing another separate page, the only way that I can think to do it is to use output control functions, or ensure that nothing is output and the whole page ends up stored in the same variable. The latter would be more efficient, I think, from a resource usage point of view. With the former you allow the page to be written to the output buffer, then capture the page using output control functions, modify what you need to and then output it. http://www.php.net/outcontrol.

Using this method you could, theoretically at least, access and modify the document similar to JavaScript on the client-side.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail
 
Old September 15th, 2004, 08:06 PM
Authorized User
 
Join Date: Nov 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jefferis Send a message via AIM to jefferis Send a message via MSN to jefferis
Default

Thanks. I guess I found it easier to do in javascript which will require less modification and programming to modify the few pages I need to.
Jeff

 function seeAll()
 {
 var metaContent = "";
 var allMetas = document.getElementsByTagName("meta");

 for(var i = 0; i < allMetas.length; i++)
 {
 if(allMetas[i].name == "description")
 {
 metaContent = allMetas[i].content;
 break;
 }
 }
 return metaContent;
 }



function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
 document.write(seeAll());

~~~~~~~~~~~~~
 http://www.petersonsales.net





Similar Threads
Thread Thread Starter Forum Replies Last Post
<meta> tag is appearing in xml file saurabh_inblore XSLT 2 April 24th, 2006 11:56 PM
meta tag rajuru Beginning PHP 1 January 30th, 2005 10:27 AM
The "Meta Refresh Tag" method nancy HTML Code Clinic 5 October 28th, 2004 04:43 PM
Need meta tag help, please larry HTML Code Clinic 1 January 6th, 2004 08:45 AM
Meta tag problem? KHarrington HTML Code Clinic 4 November 5th, 2003 12:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.