PhpDig.net

Go Back   PhpDig.net > PhpDig Forums > How-to Forum

Reply
 
Thread Tools
Old 09-13-2005, 04:16 PM   #1
mdavila
Green Mole
 
Join Date: Feb 2005
Posts: 11
Extracting H2 tag

Hi,

I have added the code you suggested to the robot_functions.php to pull the h2 tag instead of the title tag. It works but the problem is that it is pulling both the first and second h2 tags.

This is the code i pasted in:

//extracts title
if (preg_match_all('/< *h2 *>(.*?)< *\/ *h2 *>/is',$text,$regs,PREG_SET_ORDER)) {

// assumes there are at least three h2 tags
$title = trim($regs[0][1]." ".$regs[1][1]." ".$regs[2][1]);
}
else {
$title = "";
}

The results is showing " Contact UsContact Us"

On this page there are 2 h2 tags. http://dobleweb1.doble.com/contactus/ but i only want to show the second one.

Any suggestions?

Thanks,

-Marc
mdavila is offline   Reply With Quote
Old 09-14-2005, 03:59 AM   #2
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
If you only want the second H2 tag try:
Code:
$title = trim($regs[1][1]);
Instead of the following:
Code:
$title = trim($regs[0][1]." ".$regs[1][1]." ".$regs[2][1]);
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 09-14-2005, 08:02 AM   #3
mdavila
Green Mole
 
Join Date: Feb 2005
Posts: 11
When i try that. It brings up "Untitled" and "search.php" for most of them

http://doble.phpslave.com/search.php

-Marc
mdavila is offline   Reply With Quote
Old 09-14-2005, 08:57 AM   #4
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Are you using the following?
Code:
if (preg_match_all('/< *h2 *>(.*?)< *\/ *h2 *>/is',$text,$regs,PREG_SET_ORDER)) {
        // assumes there are exactly two h2 tags
        $title = trim($regs[1][1]);
}
else {
	$title = "";
}
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 09-14-2005, 09:38 AM   #5
mdavila
Green Mole
 
Join Date: Feb 2005
Posts: 11
Here is the code

//extracts title
if (preg_match_all('/< *h2 *>(.*?)< *\/ *h2 *>/is',$text,$regs,PREG_SET_ORDER)) {
$title = trim($regs[1][1]);
}
else {
$title = "";
}
mdavila is offline   Reply With Quote
Old 09-14-2005, 10:26 AM   #6
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Keep that code and increase CHUNK_SIZE in the config file, maybe 4096 will do. If not, try another increase so to get the two H2 tags in the same chunk.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 09-14-2005, 01:50 PM   #7
mdavila
Green Mole
 
Join Date: Feb 2005
Posts: 11
That seems to have done the trick!

Thanks,
-Marc
mdavila is offline   Reply With Quote
Reply


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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use variable in src tag ravi Coding & Tutorials 1 06-15-2006 06:58 AM
title tag worldwealth How-to Forum 1 12-13-2005 04:19 PM
Extracting search results and using them in your own web pages ciaran@clissman Mod Submissions 1 11-26-2005 10:14 AM
Display first H2 tag as title instead of page title mdavila How-to Forum 5 02-27-2005 06:48 PM
Custom Template Tag garyp75 How-to Forum 1 08-09-2004 02:43 PM


All times are GMT -8. The time now is 06:04 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.