JohnnyLearningPHP Posted June 25, 2009 Share Posted June 25, 2009 Hey all! Trying to use my HTML page title string as my key for one of my php variables, but I'm having a heckuva time getting PHP to access this. Anyone know of a PHP equivalent to how Javascript can call upon the document.title like so? -Johnny- Quote Link to comment https://forums.phpfreaks.com/topic/163637-php-equivalent-to-js-documenttitle/ Share on other sites More sharing options...
mattal999 Posted June 25, 2009 Share Posted June 25, 2009 Well, you would have to open the page and parse the HTML. Example from http://www.codingforums.com/archive/index.php/t-156022.html: <?php $url = "http://www.codingforums.com"; $file = file($url); $file = implode("",$file); if(preg_match("/<title>(.+)<\/title>/i",$file,$m)) { print "The title of $url is <b>$m[1]</b>"; } else { print "The page doesn't have a title tag"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163637-php-equivalent-to-js-documenttitle/#findComment-863402 Share on other sites More sharing options...
JohnnyLearningPHP Posted June 25, 2009 Author Share Posted June 25, 2009 Rock on. Is there a way for the $url variable to be the current page automatically? Quote Link to comment https://forums.phpfreaks.com/topic/163637-php-equivalent-to-js-documenttitle/#findComment-863406 Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 I found this online, that you can use to get the full, current URL: function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); } $currentURL = selfURL(); Quote Link to comment https://forums.phpfreaks.com/topic/163637-php-equivalent-to-js-documenttitle/#findComment-863408 Share on other sites More sharing options...
JohnnyLearningPHP Posted June 25, 2009 Author Share Posted June 25, 2009 Snap, I think the page's frames (not my idea) are screwing with me. Thanks for the fast response all. You totally rock. Quote Link to comment https://forums.phpfreaks.com/topic/163637-php-equivalent-to-js-documenttitle/#findComment-863419 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.