new_member Posted September 23, 2013 Share Posted September 23, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/282382-how-to-get-the-language-and-list-pages-from-site/ Share on other sites More sharing options...
.josh Posted September 23, 2013 Share Posted September 23, 2013 are you trying to get info off another site's page or make your own script aware of its own language being used? Quote Link to comment https://forums.phpfreaks.com/topic/282382-how-to-get-the-language-and-list-pages-from-site/#findComment-1450838 Share on other sites More sharing options...
new_member Posted September 23, 2013 Author Share Posted September 23, 2013 I want to get it from any other site. I have Url's of multiple sites and using that i want to get these languages for each site Quote Link to comment https://forums.phpfreaks.com/topic/282382-how-to-get-the-language-and-list-pages-from-site/#findComment-1450839 Share on other sites More sharing options...
.josh Posted September 23, 2013 Share Posted September 23, 2013 well the easiest thing would be to get the page using file_get_contents or cURL and then use the DOM parser to get it. Quote Link to comment https://forums.phpfreaks.com/topic/282382-how-to-get-the-language-and-list-pages-from-site/#findComment-1450844 Share on other sites More sharing options...
new_member Posted September 23, 2013 Author Share Posted September 23, 2013 can you give me the example how to parse and get the language of site as well as defined in html tags. I am unable to do it I have used $html = file_get_contents(url of site) What to do next?? Quote Link to comment https://forums.phpfreaks.com/topic/282382-how-to-get-the-language-and-list-pages-from-site/#findComment-1450846 Share on other sites More sharing options...
.josh Posted September 23, 2013 Share Posted September 23, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282382-how-to-get-the-language-and-list-pages-from-site/#findComment-1450847 Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282382-how-to-get-the-language-and-list-pages-from-site/#findComment-1450853 Share on other sites More sharing options...
new_member Posted September 23, 2013 Author Share Posted September 23, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/282382-how-to-get-the-language-and-list-pages-from-site/#findComment-1450855 Share on other sites More sharing options...
Solution .josh Posted September 23, 2013 Solution Share Posted September 23, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/282382-how-to-get-the-language-and-list-pages-from-site/#findComment-1450858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.