Page 1 of 1

Find a title with php

Posted: Tue May 19, 2009 5:39 pm
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>".

Re: Find a title with php

Posted: Tue May 19, 2009 5:45 pm
by andycain
Not quite sure what you mean....

Can you explain a bit more about what you want to achieve?

Re: Find a title with php

Posted: Wed May 20, 2009 7:45 am
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.

Re: Find a title with php

Posted: Wed May 20, 2009 9:32 am
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.

Re: Find a title with php

Posted: Thu May 21, 2009 6:12 pm
by JKM
But how do I make the sciript check the url's title?

Re: Find a title with php

Posted: Fri May 22, 2009 12:31 am
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*