| | |
can I get a title from an html header tag?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved
![]() |
Good morning,
Is there a php function that will take the text out of a tag in a variable that has HTML in it? What I want to do is get the text from in-between the <h1> tags and use it as a title in my meta tags.
Let's say I have all my content in separate .php files like this
Now in the php page I have
Is their any easier way? Or is this a decent way? Just trying to make it easier to add new content to my pages. thanks
Is there a php function that will take the text out of a tag in a variable that has HTML in it? What I want to do is get the text from in-between the <h1> tags and use it as a title in my meta tags.
Let's say I have all my content in separate .php files like this
PHP Syntax (Toggle Plain Text)
<?php $y ="<h1>some content</h1> this is about some content"; ?>
PHP Syntax (Toggle Plain Text)
<?php include("phpfile1.php"); ?> //this includes the doctype and the <html> and <head> tag <?php include("content.php"); ?> <?php $t=strip_tags($y); echo "<meta=\"description\" description=\"".$t."\">"; ?> //this puts a description of my content <?php include("top.php"); ?> //this includes the </head>, <body> and header html and what not <?php echo $y; ?> <?php include("footer.php"); ?> // this includes the footer html and the </body and </html>tags
Last edited by Dsiembab; Jun 23rd, 2007 at 4:06 am.
current personal projects The H8ers Club
I finally figured it out here is the code that works for me Hey thank for your reference it kind of blew my mind. I hope this helps sme people
PHP Syntax (Toggle Plain Text)
$g=strpos($y, "</h1>",1); $i=strpos($y,"<h1>",1); $f=substr($y,$i,$g); $title=strip_tags($f); echo "<title>".$title."</title>"."\n";
Last edited by Dsiembab; Jun 23rd, 2007 at 10:04 am.
current personal projects The H8ers Club
god thanks for the help. I don't know maybe I was hit in the head to many times as a child. I think what I'm hearing is, If I parse my content into arrays I can use different functions and switches and all that other funny stuff to manipulate the arrays to do my bidding. Is this so? Thanks, Dave
current personal projects The H8ers Club
•
•
•
•
god thanks for the help. I don't know maybe I was hit in the head to many times as a child. I think what I'm hearing is, If I parse my content into arrays I can use different functions and switches and all that other funny stuff to manipulate the arrays to do my bidding. Is this so? Thanks, Dave
Of course you could still code that without regular expressions, but it is more of a pain.
Last edited by iamthwee; Jun 24th, 2007 at 9:30 am.
*Voted best profile in the world*
![]() |
Similar Threads
- How to get the javascript objects in html body tag (JavaScript / DHTML / AJAX)
- php error HELP!!! (PHP)
Other Threads in the PHP Forum
- Previous Thread: Need help with If and While Clauses
- Next Thread: how do i solve the below error
| Thread Tools | Search this Thread |
# 5.2.10 access action address apache api array auto autoincrement broken cakephp checkbox class classes clean clients cms code cron curl database date dehasher destroy directory dissertation domain dropdown dynamic echo$_get[x]changingitintovariable... email encode error errorlog fairness fatalerror file folder form function functions href htaccess html image include indentedsubcategory ip javascript joomla legislation limit link load local login mail masterthesis memberships menu methods multiple multipletables mysql mysqlquery newsletters oop open passwords paypal pdf persist php popup provider query radio random script search secure server sessions simple sockets source space spam sql system table tutorial upload url user variable voteup web youtube






