Jump to content

[SOLVED] Retrieving Data from another URL's TITLE.


physaux

Recommended Posts

hey guys, I have a quick question again. How can I retrieve JUST

<title>THIS TEXT</title>

from a URL, using php?

 

I would open the file, or do a HTTP request, then search for the string with regex, but that would be really inefficient because I only want the title data. Thanks in advance!!

do you mean something like this?

 

the url:

http://domain.com/index.php?title=THIS%20TEXT

 

the code:

<html>
<head>
<?php

if(isset($_GET['title'])) {
$title = $_GET['title'];
?>
<title><?php echo $title; ?></title>
<?php
} else {
?>
<title> Title Not set </title>
<?php
}
?>
</head>
<body>

</body>
</html>

 

<?php
$url    = '[url=http://www.test.com]http://www.test.com[/url]';
$markUp = file_get_contents($url);

if ( preg_match('#<title>(.*)</title>#i', $markUp, $matches) != false)
   $title = strip_tags($matches[0]);

echo $title;

?>

 

Worst regex pattern going probably, but it's my first lol

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.