Pulling Title Tag out of HTML | | | re: Pulling Title Tag out of HTML affiliateian@gmail.com wrote: This should be easy with regular expressions. Try something like:
$text = file_get_contents($url);
preg_match('<title>(.*)</title>', $text, $matches);
$title = $matches[1]; | | | | re: Pulling Title Tag out of HTML
Message-ID: <es8kto$o5p$1@registered.motzarella.orgfrom Ulrich
Schmidt-Goertz contained the following: Quote: >
>This should be easy with regular expressions. Try something like:
>
>$text = file_get_contents($url);
>preg_match('<title>(.*)</title>', $text, $matches);
>$title = $matches[1];
And if you want your pages to validate make it http://www.stumbleupon.com/submit?ur...+Article+Title
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ | | | | re: Pulling Title Tag out of HTML
Thanks for all the replies but pretty newbie here. This is what I have
so far on the page:
<?php
$text = file_get_contents($url);
preg_match('<title>(.*)</title>', $text, $matches);
$title = $matches[1];
?>
How does one take the above and insert the variables into this URL? http://www.stumbleupon.com/submit?ur...+Article+Title
Thanks for your patience. | | | | re: Pulling Title Tag out of HTML
Message-ID: <1172825628.217900.22210@p10g2000cwp.googlegroups. comfrom affiliateian@gmail.com contained the following: Quote:
><?php
>$text = file_get_contents($url);
>preg_match('<title>(.*)</title>', $text, $matches);
>$title = $matches[1];
>?>
>
>How does one take the above and insert the variables into this URL?
>
> http://www.stumbleupon.com/submit?ur...+Article+Title
>
>Thanks for your patience.
<?php
$filename=__FILE__;
$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='http://www.stumbleupon.com/submit?url='.$_SERVER['SCRIPT_URI'].'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>' Link to stumbleupon</a>
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ | | | | re: Pulling Title Tag out of HTML
ok, running this now:
<?php
$filename=__FILE__;
$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='http://www.stumbleupon.com/submit?url='.
$_SERVER['SCRIPT_URI'].'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>' Link to stumbleupon</a>
Unfortunately, I think because we are running the php in an include
file, the echo link is not working. Viewing the php file directly
works but when this piece of code is placed in a php file inside
a .shtml file, it no longer echos the url or title.
Any ideas of how we can get around this? | | | | re: Pulling Title Tag out of HTML
Message-ID: <1172835354.325474.22650@s48g2000cws.googlegroups. comfrom affiliateian@gmail.com contained the following: Quote:
>Unfortunately, I think because we are running the php in an include
>file, the echo link is not working. Viewing the php file directly
>works but when this piece of code is placed in a php file inside
>a .shtml file, it no longer echos the url or title.
>
>Any ideas of how we can get around this?
Try this
<?php
$url=$_SERVER['SCRIPT_URI'];
$file=explode("/",$url);
$filename=$file[(count($file)-1)];
$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='http://www.stumbleupon.com/submit?url='.$url.'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>' Link to stumbleupon</a>
Bear in mind that if your <title></titleis in an include this probably
won't work.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ | | | | re: Pulling Title Tag out of HTML affiliateian@gmail.com wrote: Quote:
ok, running this now:
>
<?php
$filename=__FILE__;
$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='http://www.stumbleupon.com/submit?url='.
$_SERVER['SCRIPT_URI'].'&title='.urlencode($title);
?>
>
<a href='<?php echo $link;?>' Link to stumbleupon</a>
>
>
Unfortunately, I think because we are running the php in an include
file, the echo link is not working. Viewing the php file directly
works but when this piece of code is placed in a php file inside
a .shtml file, it no longer echos the url or title.
>
Any ideas of how we can get around this?
>
If your server is properly configured it should make no difference if
it's in an include file or not. The PHP processor should interpret any
..php file, whether called directly or included in another file.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
================== | | | | re: Pulling Title Tag out of HTML
Jerry Stuckle wrote: Quote: affiliateian@gmail.com wrote: Quote:
>ok, running this now:
>>
> <?php
>$filename=__FILE__;
>$content = implode('', file($filename));
>preg_match("/<title>(.*)<\/title>/i", $content, $match);
>$title = $match[1];
>$link='http://www.stumbleupon.com/submit?url='.
>$_SERVER['SCRIPT_URI'].'&title='.urlencode($title);
>?>
>>
><a href='<?php echo $link;?>' Link to stumbleupon</a>
>>
>>
>Unfortunately, I think because we are running the php in an include
>file, the echo link is not working. Viewing the php file directly
>works but when this piece of code is placed in a php file inside
>a .shtml file, it no longer echos the url or title.
>>
>Any ideas of how we can get around this?
>>
>
If your server is properly configured it should make no difference if
it's in an include file or not. The PHP processor should interpret any
.php file, whether called directly or included in another file.
>
OOps - lost the last part of my post.
But in you code I don't seen an echo statement. Is this the actual code
you're using?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
================== | | | | re: Pulling Title Tag out of HTML
Message-ID: <PaudnYhKldP0gXXYnZ2dnUVZ_hadnZ2d@comcast.comfro m Jerry
Stuckle contained the following: Quote:
>If your server is properly configured it should make no difference if
>it's in an include file or not. The PHP processor should interpret any
>.php file, whether called directly or included in another file.
But __FILE__ will not give him what he wants.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ | | | | re: Pulling Title Tag out of HTML
Ulrich Schmidt-Goertz wrote: Quote:
preg_match('<title>(.*)</title>', $text, $matches);
<title lang="en">My title</title>
;-)
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there! | | | | re: Pulling Title Tag out of HTML
On Fri, 02 Mar 2007 18:46:54 +0100, Toby A Inkster
<usenet200702@tobyinkster.co.ukwrote: Quote:
Ulrich Schmidt-Goertz wrote:
> Quote:
>preg_match('<title>(.*)</title>', $text, $matches);
>
<title lang="en">My title</title>
Yup, [^>]* works wonders in HTML matching.
--
Rik Wasmus | | | | re: Pulling Title Tag out of HTML
Here is the error with the new codes running:
Warning: implode() [function.implode]: Bad arguments
<?php
$url=$_SERVER['SCRIPT_URI'];
$file=explode("/",$url);
$filename=$file[(count($file)-1)];
$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='removvedbeginningportion/submit?url='.
$url.'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>'>Link to stumbleupon</a>
Jerry & Toby: Can you explain a little more? | | | | re: Pulling Title Tag out of HTML
Geoff Berrow wrote: Quote:
Message-ID: <PaudnYhKldP0gXXYnZ2dnUVZ_hadnZ2d@comcast.comfro m Jerry
Stuckle contained the following:
> Quote:
>If your server is properly configured it should make no difference if
>it's in an include file or not. The PHP processor should interpret any
>.php file, whether called directly or included in another file.
>
>
But __FILE__ will not give him what he wants.
Good point, Geoff - one that I missed.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
================== | | | | re: Pulling Title Tag out of HTML affiliateian@gmail.com wrote: Quote:
Here is the error with the new codes running:
>
Warning: implode() [function.implode]: Bad arguments
>
<?php
$url=$_SERVER['SCRIPT_URI'];
$file=explode("/",$url);
$filename=$file[(count($file)-1)];
$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='removvedbeginningportion/submit?url='.
$url.'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>'>Link to stumbleupon</a>
>
Jerry & Toby: Can you explain a little more?
>
It usually means the second parameter isn't an array.
Try adding this before your implode:
echo $filename . "<br>\n";
echo "<pre>\n";
print_r(file($filename));
echo "</pre>\n";
This should print the file name followed by the file. Is the filename
correct, and if so, are you actually able to open (and display) it?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
================== | | | | re: Pulling Title Tag out of HTML
Try adding this before your implode: Quote:
>
echo $filename . "<br>\n";
echo "<pre>\n";
print_r(file($filename));
echo "</pre>\n";
ok, added it and still got implode error. Commented out implode line
and got an echo to show, but no url or title. Here is what we have.
Any ideas?
<?php
$url=$_SERVER['SCRIPT_URI'];
$file=explode("/",$url);
$filename=$file[(count($file)-1)];
echo $filename . "<br>\n";
echo "<pre>\n";
print_r(file($filename));
echo "</pre>\n";
//$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link=removedtodisplayproperlyhere.com/submit?url='.
$url.'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>'>Link to stumbleupon</a> | | | | re: Pulling Title Tag out of HTML affiliateian@gmail.com wrote: Quote: Quote:
>Try adding this before your implode:
>>
>echo $filename . "<br>\n";
>echo "<pre>\n";
>print_r(file($filename));
>echo "</pre>\n";
>
ok, added it and still got implode error. Commented out implode line
and got an echo to show, but no url or title. Here is what we have.
Any ideas?
>
<?php
$url=$_SERVER['SCRIPT_URI'];
$file=explode("/",$url);
$filename=$file[(count($file)-1)];
echo $filename . "<br>\n";
echo "<pre>\n";
print_r(file($filename));
echo "</pre>\n";
//$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link=removedtodisplayproperlyhere.com/submit?url='.
$url.'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>'>Link to stumbleupon</a>
>
You got an echo to show - but was it the right information?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
================== | | | | re: Pulling Title Tag out of HTML
You got an echo to show - but was it the right information?
The echoed link was missing the url & title content. Only the skeleton
link to SU. Anything else we can try here? Thanks for the help! | | | | re: Pulling Title Tag out of HTML
Rik wrote: Quote:
Yup, [^>]* works wonders in HTML matching.
<title foo=">" bar="quux">My Title</title>
;-)
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there! | | | | re: Pulling Title Tag out of HTML
On Sat, 03 Mar 2007 00:46:27 +0100, Toby A Inkster
<usenet200702@tobyinkster.co.ukwrote: Quote:
Rik wrote:
> Quote:
>Yup, [^>]* works wonders in HTML matching.
>
<title foo=">" bar="quux">My Title</title>
>
;-)
Yeah, yeah, shouldn't be offcourse (foo=">"), but hey: that's why you
normally parse html, not match it :-)
--
Rik Wasmus | | | | re: Pulling Title Tag out of HTML affiliateian@gmail.com wrote: Quote: Quote:
>You got an echo to show - but was it the right information?
>
The echoed link was missing the url & title content. Only the skeleton
link to SU. Anything else we can try here? Thanks for the help!
>
Well, that explains why your implode fail then, doesn't it?
But specifically, what was in the echoed link? And what did you expect
to see?
I'm trying to help, but without the information I'm asking for, you make
it almost impossible to give you a good answer.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
================== | | | | re: Pulling Title Tag out of HTML
I'm trying to help, but without the information I'm asking for, you make Quote:
it almost impossible to give you a good answer.
Hey Jerry,
First of all, know that your help is really appreciated. Being a
newbie at coding, I am still trying to follow the lingo. Sorry about
missing some info. Let me try it here.
Running this:
<?php
$url=$_SERVER['SCRIPT_URI'];
$file=explode("/",$url);
$filename=$file[(count($file)-1)];
echo $filename . "<br>\n";
echo "<pre>\n";
print_r(file($filename));
echo "</pre>\n";
//$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='edited-so-url-displays://www.stumbleupon.com/submit?url='.
$url.'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>'>Link to stumbleupon</a>
Resulting HTML is:
<a href='http://www.stumbleupon.com/submit?url=&title='>Link to
stumbleupon</a>
Want to get this:
<a href='http://www.stumbleupon.com/submit?url=http://www.mydomain.com/
file.html&title=Title of file.html'>Link to stumbleupon</a>
How was that? | | | | re: Pulling Title Tag out of HTML
Message-ID: <1172871036.728685.248460@v33g2000cwv.googlegroups .comfrom affiliateian@gmail.com contained the following: <shrug>It works on my machine
You have to learn to debug code. Work through it so you understand it
and echo the variables to make sure they contain what they should. //assigns the script uri to the variable $url. echo it out to check Quote:
>$url=$_SERVER['SCRIPT_URI'];
//splits the uri into sections and creates an array of the pieces. Quote:
>$file=explode("/",$url);
//use print_r($file) to see what it contains
//get the last piece. This should be the file name or the page we are on Quote:
>$filename=$file[(count($file)-1)];
>echo $filename . "<br>\n";
/you echoed it. Was it what it was supposed to be?
//If it's not the filename of the page we are on
//then that's why implode will fail Quote:
>echo "<pre>\n";
>print_r(file($filename));
>echo "</pre>\n";
//the next line gets the contents of the file and puts it
//into a string called $content so we can do the matching
// Quote:
>//$content = implode('', file($filename));
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ | | | | re: Pulling Title Tag out of HTML
Message-ID: <olmhu2ln294ghk1e8pkatqo60e8j2caevh@4ax.comfrom Geoff
Berrow contained the following: Quote:
> >
><shrug>It works on my machine
Scratch that, it doesn't.
The variable $_SERVER['SCRIPT_URI'] was not available .
Try this
<?php
$url=$_SERVER['SCRIPT_FILENAME'];
$file=explode("/",$url);
$filename=$file[(count($file)-1)];
$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='http://www.stumbleupon.com/submit?url='.$url.'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>' Link to stumbleupon</a>
Failing that try
$_SERVER['REQUEST_URI']
or
$_SERVER['SCRIPT_NAME']
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ | | | | re: Pulling Title Tag out of HTML affiliateian@gmail.com wrote: Quote: Quote:
>I'm trying to help, but without the information I'm asking for, you make
>it almost impossible to give you a good answer.
>
Hey Jerry,
>
First of all, know that your help is really appreciated. Being a
newbie at coding, I am still trying to follow the lingo. Sorry about
missing some info. Let me try it here.
>
Running this:
>
<?php
$url=$_SERVER['SCRIPT_URI'];
$file=explode("/",$url);
$filename=$file[(count($file)-1)];
echo $filename . "<br>\n";
echo "<pre>\n";
print_r(file($filename));
echo "</pre>\n";
//$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='edited-so-url-displays://www.stumbleupon.com/submit?url='.
$url.'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>'>Link to stumbleupon</a>
>
Resulting HTML is:
>
<a href='http://www.stumbleupon.com/submit?url=&title='>Link to
stumbleupon</a>
>
Want to get this:
>
<a href='http://www.stumbleupon.com/submit?url=http://www.mydomain.com/
file.html&title=Title of file.html'>Link to stumbleupon</a>
>
How was that?
>
OK, so look at your code and what's different between what you get and
what you want?
Two things. First of all $url isn't displaying the correct info - so it
must be incorrect. What's in it? echo before your code and I suspect
you'll find it's empty. So maybe $_SERVER['SCRIPT_URI'] is incorrect,
Use print_r() to figure out what's in it.
The next problem is $title doesn't seem to contain the correct
information. But that's ok because your implode is commented out.
But notice that $filename in your implode() function call eventually
comes from $url, also.
Hmmm, two different problems, but both with the same source. What do
you want to bet $url doesn't have the information you want? echo it to
the display and see what it actually has.
BTW - I agree with Geoff. You need to develop some debugging
techniques. With some decent techniques you should be able to determine
the cause of your problem in 10-15 minutes, instead of a couple of days
trying to converse here on usenet.
That's not saying I won't continue to try to give you a hand here. But
you're going to need those techniques the more you program.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
================== | | | | re: Pulling Title Tag out of HTML
Geoff Berrow wrote: Quote:
Message-ID: <olmhu2ln294ghk1e8pkatqo60e8j2caevh@4ax.comfrom Geoff
Berrow contained the following:
> Quote: ><shrug>It works on my machine
>
Scratch that, it doesn't.
The variable $_SERVER['SCRIPT_URI'] was not available .
>
Try this
>
<?php
$url=$_SERVER['SCRIPT_FILENAME'];
$file=explode("/",$url);
$filename=$file[(count($file)-1)];
$content = implode('', file($filename));
preg_match("/<title>(.*)<\/title>/i", $content, $match);
$title = $match[1];
$link='http://www.stumbleupon.com/submit?url='.$url.'&title='.urlencode($title);
?>
<a href='<?php echo $link;?>' Link to stumbleupon</a>
>
>
>
>
Failing that try
$_SERVER['REQUEST_URI']
or
$_SERVER['SCRIPT_NAME']
>
It's available on my (Debian) Linux system with Apache 2.0.sumthun.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
================== | | | | re: Pulling Title Tag out of HTML
Message-ID: <pKSdnSIk36mSeXXYnZ2dnUVZ_trinZ2d@comcast.comfro m Jerry
Stuckle contained the following: Quote:
>It's available on my (Debian) Linux system with Apache 2.0.sumthun.
Yeah, it was available on my webhost but not when I checked on my local
setup. Bit busy yesterday, couldn't remember where I'd tested it.
Incidentally, for the OP. To check what $_SERVER variables /are/
available do this:
foreach($_SERVER as $key=>$value){
echo"Key is: $key Value is:$value<br>";
}
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|