Quick question for everyone!<

liunx

Guest
Hey all,


I have a website, a.html let's say, and inside of it we have
<title>Red</title>

Is there a way to obtain the value 'Red' from another website(perhaps one that is called using the post or get method to bring over the form dataset)? Or is there a way to find out what the title of the page is called within the page itself? Maybe further down in the body, for example, can I output the webpage title?
I know, for example, in PHP you just put $ in front of the name in the form data to grab the value associated with it, however I have never heard of grabbing the actual title. Any ideas??

Thanks all!

-TekYou can do that with Perl or PHP. With Perl you use the LWP module to get the webpage and probably HTML::Parser to find the html element that interests you. But I have no pratical experience with doing it myself, so you may want to wait for other replies or try reading the Perl docs for LWP

<!-- m --><a class="postlink" href="http://www.perldoc.com/perl5.8.4/pod/perlfaq9.html#How-do-I-fetch-an-HTML-file-">http://www.perldoc.com/perl5.8.4/pod/pe ... HTML-file-</a><!-- m -->

if you can't use HTML::Parser, then you can try pulling the stuff you want out using regexps:

$whatever =~ m/<title>(.*?)</title>/i;
$the_title = $1;

something like that might work.Well, at this point i'd wager this is going to have to be moved to the php subforum, however what would be the proper solution to do this in php? I have seen examples where you would need to parse the entire html code, look for <title> tag, and get what is in between in. Unfortunately, my method must be different from this one, because the pages i will be getting the title from will have different (and unknown) website names.

Any idea?

Thanks!

Tekif its a PHP solution you prefer then the PHP forum would be the place to post the thread :)


moving thread.......... now! :DI'm far from an expert on regular expressions, almost as far as you can get, but that would be how I would do it.

I would use fopen() (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.fopen.php">http://www.php.net/manual/en/function.fopen.php</a><!-- m -->) to open the page and fread() (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.frea.php">http://www.php.net/manual/en/function.frea.php</a><!-- m -->) to read the file into a variable. Then I would try to figure out how to use either eregi() (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.eregi.php">http://www.php.net/manual/en/function.eregi.php</a><!-- m -->) or preg_match() (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.preg-match.php">http://www.php.net/manual/en/function.preg-match.php</a><!-- m -->).yup, bica has it correct. you need to use regular expressions to get the contents of a tag.

preg_match('/<title>(.*)</title>/', $matches)

echo $matches[1];

it should echo the contents between the title tags.Small change:

<?php
$string = "<title>Test Title</title><body>";
preg_match('/<title>(.*)<\/title>/', $string, $matches);
echo $matches[1];
?>ahh, I knew I shouldn't have taken it from memory.:P thanks torrent bud, glad to see ya again. :);) np's

we've had some fun with those reg exps over the years mate :)ooo this is awesome. so i use fopen() and fread()? i'm used to using file() to read files into arrays... but to be safe i'll use fread(). hopefully there's not much difference between that and file() but i'll look it up at php.net. thanks all.
 
Back
Top