Find a title with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Find a title with php

Post by JKM »

Is it possible to find a title with a form where you submit an url (f.i. "viewtopic.php?f=1&t=100407"). When pressing submit, it should echo the text between "<title>DevNetwork Forums &bull; " and "</title>".
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Re: Find a title with php

Post by andycain »

Not quite sure what you mean....

Can you explain a bit more about what you want to achieve?
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: Find a title with php

Post by JKM »

Code: Select all

<?php
if($_POST['submit']) {
    /*
    Find $_POST['link']'s title (only the text between "<title>DevNetwork Forums &bull; View forum - " and "</title>" (if viewforum.php?f=1 were the url, it should echo 'PHP - Code'.
    */
    echo $title;
} else {?>
<form enctype="multipart/form-data" action="" method="post">
    <input name="link" type="text" /><br />
    <input name="submit" type="text" />
</form>
<?php
}
?>
Like this.
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Re: Find a title with php

Post by andycain »

Yes you can do this.

Pass the text in between the <title> </title> tages into a variable.

Then use the PHP explode function to split the string into smaller strings.

All you need to do then is call the appropriate exploded string that contains the part of the title you need.
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: Find a title with php

Post by JKM »

But how do I make the sciript check the url's title?
Scriptor
Forum Newbie
Posts: 9
Joined: Fri May 22, 2009 12:27 am

Re: Find a title with php

Post by Scriptor »

Code: Select all

 
<?
$url=file_get_contents("http://www.devnetwork.net");
preg_match('/<title>(.*)<\/title>/i',$url,$output);
echo "Page title: \"".$output[1]."\"";
?>
 
should work*
Post Reply