rhysmeister Posted March 11, 2009 Share Posted March 11, 2009 Hi is it possible to dynamically unload or disable a certain extension from a php script? I want to disable DOMXML for a certain script. Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/ Share on other sites More sharing options...
rhodesa Posted March 11, 2009 Share Posted March 11, 2009 not that i'm aware of...why would you want to disable it? Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-782046 Share on other sites More sharing options...
rhysmeister Posted March 11, 2009 Author Share Posted March 11, 2009 This solution advises it (see bottom) http://forums.digitalpoint.com/showthread.php?t=833 Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-782221 Share on other sites More sharing options...
rhodesa Posted March 11, 2009 Share Posted March 11, 2009 ah...XML. can you elaborate on what you are trying to accomplish? there is probably another option Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-782223 Share on other sites More sharing options...
rhysmeister Posted March 11, 2009 Author Share Posted March 11, 2009 I just want to get the title of a web page from any given url. I run a url shortenign service and I post a small number of links to twitter. It'll just be a nice touch to add the title of the html page. Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-782229 Share on other sites More sharing options...
rhodesa Posted March 11, 2009 Share Posted March 11, 2009 ok...in that case...you don't want to use an XML parser. if the page doesn't validate as strict XHTML (which MOST pages don't) you won't be able to retrieve it. Instead, get it with regular expressions: <?php $contents = file_get_contents('http://www.cnn.com'); if(preg_match('/<title>(.+?)<\/title>/',$contents,$matches)){ $title = $matches[1]; print $title; } ?> Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-782234 Share on other sites More sharing options...
rhysmeister Posted March 11, 2009 Author Share Posted March 11, 2009 ok...in that case...you don't want to use an XML parser. if the page doesn't validate as strict XHTML (which MOST pages don't) you won't be able to retrieve it. Instead, get it with regular expressions: Very good point. I went for DOM because it would't matter if the title tags were on different lines. I might try to stip out any newline characters. Thanks, I will give your approach a go this evening. Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-782318 Share on other sites More sharing options...
rhysmeister Posted March 11, 2009 Author Share Posted March 11, 2009 Added in $contents = preg_replace("/\n|\r\n|\r$/", "", $contents); and it seems to get around the issue of title tags being on different lines. Thanks for your help. Rhys Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-782385 Share on other sites More sharing options...
redarrow Posted March 11, 2009 Share Posted March 11, 2009 what about using str_replace instead then? Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-782394 Share on other sites More sharing options...
rhodesa Posted March 11, 2009 Share Posted March 11, 2009 you should just be able to use <?php $contents = file_get_contents('http://www.cnn.com'); if(preg_match('/<title>(.+?)<\/title>/s',$contents,$matches)){ $title = $matches[1]; print $title; } ?> Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-782419 Share on other sites More sharing options...
rhysmeister Posted March 15, 2009 Author Share Posted March 15, 2009 Thanks, that nearly got it. Changed to '/<title>(.+?)<\/title>/si' to make the search case insensitive. I've always shied away from regular expressions so never think to use them. Guess I shouldn't! Link to comment https://forums.phpfreaks.com/topic/148940-unload-an-extension-from-a-php-script/#findComment-785197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.