plznty Posted September 28, 2009 Share Posted September 28, 2009 How would I go about using PHP to get bits of a page for example. example.com/index.html - <html> <title>Example page 1</title> </html> How would I use php on my page to just gather the "Example page 1" part and not the rest. Could you give me the php how I would do that for this particular example of explain please. Would be appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/175782-solved-how-to-get-segments-from-a-page/ Share on other sites More sharing options...
trq Posted September 28, 2009 Share Posted September 28, 2009 $s = '<html><title>Example page 1</title></html>'; preg_match('/<title>(.*)<\/title>/', $s, $m); echo $m[1]; Link to comment https://forums.phpfreaks.com/topic/175782-solved-how-to-get-segments-from-a-page/#findComment-926291 Share on other sites More sharing options...
plznty Posted September 28, 2009 Author Share Posted September 28, 2009 $s = '<html><title>Example page 1</title></html>'; preg_match('/<title>(.*)<\/title>/', $s, $m); echo $m[1]; is there a way i can do it without having to insert thier page code. Something like include. So it could be updatable as the other page updates. Link to comment https://forums.phpfreaks.com/topic/175782-solved-how-to-get-segments-from-a-page/#findComment-926296 Share on other sites More sharing options...
trq Posted September 28, 2009 Share Posted September 28, 2009 I'm not sure what you mean exactly, but you could simply put the page into a string. eg; $s = file_get_contents('somepage.html'); preg_match('/<title>(.*)<\/title>/', $s, $m); echo $m[1]; Link to comment https://forums.phpfreaks.com/topic/175782-solved-how-to-get-segments-from-a-page/#findComment-926304 Share on other sites More sharing options...
plznty Posted September 28, 2009 Author Share Posted September 28, 2009 Example.com/index1.html on 01/01/2010 <html> <title>Example page 1</title> </html> Example.com/index2.html on 02/01/2010 <html> <title>Example page 2</title> </html> Ide like my page to be able to pickup the current title part. So must need to get information from external sources rather than pasting in my own page Link to comment https://forums.phpfreaks.com/topic/175782-solved-how-to-get-segments-from-a-page/#findComment-926307 Share on other sites More sharing options...
trq Posted September 28, 2009 Share Posted September 28, 2009 So pass the url to file_get_contents. Link to comment https://forums.phpfreaks.com/topic/175782-solved-how-to-get-segments-from-a-page/#findComment-926316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.