jmhyer123 Posted May 24, 2007 Share Posted May 24, 2007 I am working on a script at the moment and I am trying to read the title of the page (between <title> and </title> tags) I can't figure out how to do it in PHP so I was trying to use javascript since it is way easier. However I can't get it to work. Heres the code: $pagetitle = "<script language=javascript>document.title</script>"; I have tried chaning it (using " or ' around language=javascript) and I know that is the correct javascript because if you plug it into your brower as javascript:document.title it returns the title. If anybody has figured this out before or if anybody knows how to do this (read the title) with PHP that would be great! Thanks in advance!! Jeffrey Quote Link to comment https://forums.phpfreaks.com/topic/52741-solved-php-w-javascript-as-variable-help-plz/ Share on other sites More sharing options...
marcus Posted May 24, 2007 Share Posted May 24, 2007 $fh = fopen($DOCUMENT_ROOT.$PHP_SELF,"r"); $found=false; $title=""; while(!feof($fh) && !found){ if(preg_match("/<title>(.*)<\\\/title>/",fget($fh,4096),$matches)){ $found=true; $title=$matches[1]; } } fclose($fh); if($found){ // Here title is correct } else{ // this page doesn't contain <title> } http://www.dmxzone.com/forum/topic.asp?topic_id=14764 Quote Link to comment https://forums.phpfreaks.com/topic/52741-solved-php-w-javascript-as-variable-help-plz/#findComment-260415 Share on other sites More sharing options...
hitman6003 Posted May 24, 2007 Share Posted May 24, 2007 php and javascript don't interact like that...JS is client side, php is serverside...and they don't talk directly. You'll have to read the html for the page into a variable, then use regex to get the title out of that text. Quote Link to comment https://forums.phpfreaks.com/topic/52741-solved-php-w-javascript-as-variable-help-plz/#findComment-260417 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.