Jump to content

how to get the language and list pages from site


new_member

Recommended Posts

Hi,

 

I want to get the language defined in html or meta tags using php as <html lang="en"> using php. I have searched a lot in google but cannot find any way. Similarly i also want to get the language in site being used as if the site text is in japanese there shoould be any function to return the japense language using php. Is there any way to do this?? urgent help needed. Thanks

I pointed you in the right direction. There are a shitton of tuts out there for scraping pages in general or using DOM. I'm not going to regurgitate that here. If you have some specific issue we'll be happy to help or point you in the right direction, but as it stands now, this sounds like a thinly veiled "write my script for me" request - something we don't do.

Have a look at the example code @ http://www.phpro.org/examples/Parse-HTML-With-PHP-And-DOM.html

 

Play around with that. Read the documentation for using DOM ( .josh probided a link earlier). You should be able to get lang attribute for the html tag in just a few lines of code. All it takes is for you sit down read documentation testing/playing with examples and then you should be able to implement this yourself.

I have used

 

$dom = new DOMDocument();
$dom->loadHTML($file);
$node = $dom->getElementById("registryData");
$output = $dom->saveHTML($node);

echo $output;

 

 

However i have used many other codes like this to parse the data within the html tages like anchor tags, img etc but i cannot find any way to find the language used.

Think about what you are trying to get. Read what getElementById does. Do you think it is going to give you the page language? page language will either be in the html tag or a meta tag, neither of which has an id attribute. You will need to use getElementsByTagName and then loop through them checking for appropriate attributes using getAttribute

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.