Jump to content
  • Advertisement
Sign in to follow this  
ballack

meta tags how to process it

This topic is 4965 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi i am trying to do a search Engine .can anyone tell me how can i process information on a Meta tag using some scripting lang.

Share this post


Link to post
Share on other sites
Advertisement
You mean HTML meta tags?
What scripting langauge?

I can show you how to do it in C++, assuming the tag is of the format <meta name="tagname" content="tagcontent"> it's easy:

bool ProcessMetaTag(const string& strTag, string& strName, string& strContent)
{
string strIn(strTag);

// Check it starts with "<meta"
if(stricmp(strIn.sub(0,5).c_str(),"<meta") != 0)
retrun false;
strIn.erase(strIn.begin(),strIn.begin()+5);

// Trim whitespace //
while(strIn[0] == ' ') strIn.erase(strIn.begin());

// Extract 'name="' part //
if(stricmp(strIn.sub(0,6).c_str(),"name=\"") != 0)
retrun false;
strIn.erase(strIn.begin(),strIn.begin()+6);

// Find end of tag //
int nPos = strIn.find('\"');
if(nPos == string::npos)
return false;

// Save name tag //
strName = strIn.substr(0,nPos);
strIn.erase(strIn.begin(),strIn.begin()+nPos+1);

// Trim whitespace //
while(strIn[0] == ' ') strIn.erase(strIn.begin());

// Extract 'content="' part //
if(stricmp(strIn.sub(0,9).c_str(),"content=\"") != 0)
retrun false;
strIn.erase(strIn.begin(),strIn.begin()+9);

// Find end of tag //
int nPos = strIn.find('\"');
if(nPos == string::npos)
return false;

// Save content tag and return //
strContent = strIn.substr(0,nPos);
return true;
}




That's totally off the top of my head, and isn't at all robust.

Share this post


Link to post
Share on other sites
If you're going to write this in C++ you can also use some regular expression library, like the one supplied by Boost. Unfortunately I haven't had the time yet to look into it myself.

Most scripting languages also support regular expressions. Make use of them while parsing text!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!