Closed Thread Icon

Topic awaiting preservation: PHP: accessing title of page? (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=11992" title="Pages that link to Topic awaiting preservation: PHP: accessing title of page? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP: accessing title of page? <span class="small">(Page 1 of 1)</span>\

 
GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 01-11-2002 16:32

is there a method to read/write the title of a page with php only? (no JS)

html->head->title tag i mean.

i wanna add something to the title-string by the end of the site. (after the head - tag)



InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-11-2002 16:55

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 01-11-2002 17:00

yes, but there is html before the php-code. so i thought, there would be a way to read that value.

but i think, i'll use JS to do that. it's a bit more complicated but it'll work.
that's document.title right?

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 01-11-2002 17:06

GRUMBLE: I'm wondering why? Is it your own page? There might be an easier way.

Emps

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-11-2002 17:31

well, Grumble, there is an overkill solution to this :-)
call ob_start() at the beginning of your script.
then you do whatever your script does, but instead of a real title write something like '%%REPLACE_ME%%'.
then get the buffered output into a string. strreplace() to replace the %%REPLACE_ME%% and then, end the output buffering and output the string... see the php manual section about output buffering for details...

hope this helps,

Tyberius Prime

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 01-11-2002 17:42

emps, yes it is my page. what easier way is there? (i want to add a string which i read out of a mysql-db to my title)

tyberius, nice solution. but as i said, in my case i want to add something, so i also have to read out the existing title.
example:

code:
blabla.com :: random quote :: document title
php mysql

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 01-11-2002 18:00

GRUMBLE: Well there might not be an easier way but try something like this (I use it a lot):

code:
<title>My site: <?php echo "$some_text"; ?></title>



However this seems a little simple but it can be fed in from outside includes, etc. Just make sure you grab the $some_text beforehand. As I say this sounds too simple and I wonder if I've understood the problem correctly.

Emps


You're my wife now Dave

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 01-11-2002 18:11

ok then, but how do i read/write to it afterwards. content should be filled by a mysql-query which is called in an include AFTER the title-tag.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 01-11-2002 18:20

GRUMBLE: This is where I thought the problems might arise - again this sounds too simplistic but can't you have the include above the <TITLE>? I like to try and keep the HTML and PHP as separate as possible and the majority of the PHP done before the HTML and then drop the PHP into the right places in the HTML. There are just so many different ways of doing this that it might not be very helpful for your approach.

Emps


You're my wife now Dave

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 01-11-2002 18:33

How we do it is assign a basic title, such as "GurusNetwork.com" in the <head>.

Then, in the body, read your DB from PHP, and get the "real" title, and use javascript to change the page title to what it should be:

<script language=JavaScript type=text/JavaScript>
<!-- Enable Stealth Mode
document.title=(document.title + " - " + <?=$title ?> );
// Disable Stealth Mode -->
</script>

We then end up with "GurusNetwork.com - My Title from PHP"



[This message has been edited by Pugzly (edited 01-11-2002).]

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 01-11-2002 18:40

emps, yes i could do the mysql-query before the head, but i was trying to avoid that.

pugzly, yes, actually i am using exactly this way!
so i asked if there was a non-JS version too. seems no.
ok. i'll stick with this.

[This message has been edited by GRUMBLE (edited 01-11-2002).]

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-11-2002 18:41

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-12-2002 00:01

also, you could use my solution and use a title like 'blabla.com :: %%REPLACEME1%% :: %%REPLACEME2%%.
or something similar. Provided that it's always the same place you have to append whatever you have to append :-)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 01-12-2002 01:50

I am having trouble figuring out why you would not want to place the query at the beginning of your document. The only reason I could see you placing it in the middle would be if you were to be pulling in the content from another page and have the code placed in that page, and if this is how you are working it, i would find it much better to then seperate your code and call the code at the beginning of the page as oposed to the middle.

In all other instances it would be much more effective to have all of your PHP code at the beginning of your page. From there you can do all of your processing, call all of your headers and create all of your variables in one location. This way you only need to echo the appropriate content, and avoid many of the maintainace problems.

If you could show us your code I am sure that we could come up with a much better solution for you. I think after all is said and done we are simple offering solutions of theory, on how we picture your code to look.



-mage-

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 01-12-2002 01:58

Yeah, I second WarMage's suggestion.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 01-12-2002 05:38

That's not always easy....

Let's say you have a header page that's included at the top of several templates. If each template pulls different data, then you can't really have the query in that included header page. It need to go in the content page, unless you're going to overly complicate the scripting......

SunSet
Nervous Wreck (II) Inmate

From: The Lost City Of Atlantis
Insane since: Aug 2001

posted posted 01-12-2002 20:50

This might be helpfull...... read me

« BackwardsOnwards »

Show Forum Drop Down Menu