ballhogjoni Posted January 24, 2008 Share Posted January 24, 2008 I want to echo the title of the page in a URL string. Is there a function were I can do this? example: <a href="http://test.com?ex=ex&title=<?php echo [title of page]; ?> Link to comment https://forums.phpfreaks.com/topic/87638-is-there-a-function-for-this/ Share on other sites More sharing options...
PHP Monkeh Posted January 24, 2008 Share Posted January 24, 2008 Title as in the <title> or the name of the file itself (excluding extensions)? Link to comment https://forums.phpfreaks.com/topic/87638-is-there-a-function-for-this/#findComment-448231 Share on other sites More sharing options...
ballhogjoni Posted January 24, 2008 Author Share Posted January 24, 2008 <title> tag eg. <title>Test</title> I want the url to have just the word test in it. Link to comment https://forums.phpfreaks.com/topic/87638-is-there-a-function-for-this/#findComment-448234 Share on other sites More sharing options...
PHP Monkeh Posted January 24, 2008 Share Posted January 24, 2008 You'd have to set up reading the file and then doing matches with regex. Something like this: <?php $text = "READ YOUR HTML IN TO THIS STRING"; preg_match("/\<title\>(.*)\<\/title\>/", $text, $matches); echo $matches[1]; ?> Aslong as all your HTML is in $text it'll output whatever's in between <title> and </title> Link to comment https://forums.phpfreaks.com/topic/87638-is-there-a-function-for-this/#findComment-448274 Share on other sites More sharing options...
resago Posted January 24, 2008 Share Posted January 24, 2008 try <a href="http://test.com?ex=ex&title=<?php echo preg_replace('/.*<title>(.*)<\/title>.*/si',"$1",file_get_contents("http://test.com?ex=ex")); ?> Link to comment https://forums.phpfreaks.com/topic/87638-is-there-a-function-for-this/#findComment-448276 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.