~~~ PHP NEWBIE HELP ~~~~
My problem is a simple one.
Calling a function to fill form.
To see what I on about copy and save
every thing below below as a HTML doc
I did it this way as there are two forms
you should see.
Greg🙂
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.72 [en] (Win98; U) [Netscape]">
<title>Adding a entry</title>
<script language="javascript" type="text/javascript">
<!--
function checkurl(){
checkkeywords();
}
function checktype(){
checktitle();
}
function checktitle(){
checkdescription();
}
function checkdescription(){
checkurl();
}
function checkkeywords(){
checkauthor();
}
function checkauthor(){
document.addform.submit();
}
//-->
</script>
</head>
<body>
<div class="header">
<div align="center">
<p>Adding a entry: Problem</p>
<p align="left">The user submits a URL in form below.<br>
This should then call the function metaengine(); <br>
In file: tags.php3 (see below at bottom of page).<br>
<br>
The function should then generate or autofill the second page <br>
below with the retrieved META data. So that the file can then be submitted to
the database.</p>
<p align="left">(e.g. $meta[title], $meta[keywords], $meta[description])</p>
<p align="left">I know this is really easy but I'm very new to PHP and am not quite
sure how to go about this. If anyone could help me out on this problem it would proberly save me
some time.</p>
<p align="left">Greg :-)</p>
<p align="left"> </p>
<p>This is the form that the user will see on the first page. </p>
<form method="post" action="">
<input type="text" size="40" name="url2" maxlength="200" value="http://">
<input type="submit" name="Submit" value="Submit">
</form>
<p> <br>
##########################################################################
</p>
<p>Second Page</p>
<p>Form to be filled or generated so it can be submitted to database.</p>
</div>
</div>
<form name="addform" action="add.php">
<center>
<table border=0 cellspacing=0 cellpadding=0 cols=2 width="100%" height="100%" >
<tr>
<td width="36%">
<div align=right>Url: </div>
</td>
<td width="64%">
<input type="text" size="40" name="url" maxlength="200" value="http://">
<br>
</td>
</tr>
<tr>
<td width="36%">
<div align=right>Type: </div>
</td>
<td width="64%">
<input type="text" size="5" name="type" value="html">
<br>
</td>
</tr>
<tr>
<td width="36%">
<div align=right>Title: </div>
</td>
<td width="64%">
<input type="text" size="40" name="title" maxlength="80">
<br>
</td>
</tr>
<tr>
<td width="36%">
<div align=right>Description: </div>
</td>
<td width="64%">
<input type="text" size="45" name="description" value="" maxlength="250">
<br>
</td>
</tr>
<tr>
<td width="36%">
<div align=right>Keywords: <font size="1"><br>
(coma, separated)</font> </div>
</td>
<td width="64%">
<input type="text" size="40" name="keywords" maxlength="300">
<br>
</td>
</tr>
<tr>
<td width="36%">
<div align=right>Author: </div>
</td>
<td width="64%">
<input type="text" size="20" name="author" maxlength="50">
</td>
</tr>
</table>
<br>
</center>
<center>
<input type="button" value="Submit" onClick="checktype()" >
</center></form>
<p> </p>
<p> </p>
<p>tags.php3 </p>
<p><?php // metaengine.php3</p>
<p></p>
<p> /************************************************************************<br>
FILE: tags.php3<br>
<br>
FUNCTION: metaengine();<br>
<br>
INPUT: Any URL value, ($url);<br>
OUTPUT: An array of meta tag information, where the name <br>
attribute of the meta tag is the key value of the array.<br>
(e.g. $meta[title], $meta[keywords], $meta[description])<br>
<br>
DESCRIPTION: This function was created because the get_meta_tags()<br>
function does not properly return meta information if the<br>
requested file is not formated correctly or if newline,<br>
return, and tab characters are present within the meta tag.<br>
<br>
NOTES: This function will only return meta information for title,<br>
keywords, and description.<br>
********************************************************************/</p>
<p>function metaengine($url)<br>
{<br>
// Pattern for meta title<br>
$p_title[0] = '(<title>)([a-zA-Z_0-9@!%-;&`,\'\+\$\.\n\t\r ]+)';<br>
$p_title[1] = '(<meta)([[:space:]]+)(name="title")([[:space:]]+)(content=")([a-zA-Z_0-9@!%-;&`,\'\+\$\.\n\t\r
]+)';<br>
$p_title[2] = '(<meta)([[:space:]]+)(name=title)([[:space:]]+)(content=)([a-zA-Z_0-9@!%-;&`,\'\+\$\.\n\t\r
]+)';</p>
<p> // Pattern for meta description<br>
$p_description[0] = '(<meta)([[:space:]]+)(name="description")([[:space:]]+)(content=")([a-zA-Z_0-9@!%-;&`,\'\+\$\.\n\t\r
]+)';<br>
$p_description[1] = '(<meta)([[:space:]]+)(name=description)([[:space:]]+)(content=)([a-zA-Z_0-9@!%-;&`,\'\+\$\.\n\t\r
]+)';<br>
<br>
// Pattern for meta keywords<br>
$p_keywords[0] = '(<meta)([[:space:]]+)(name="keywords")([[:space:]]+)(content=")([a-zA-Z_0-9@!%-;&`,\'\+\$\.\n\t\r
]+)';<br>
$p_keywords[1] = '(<meta)([[:space:]]+)(name=keywords)([[:space:]]+)(content=)([a-zA-Z_0-9@!%-;&`,\'\+\$\.\n\t\r
]+)';<br>
$p_keywords[2] = '(</head>)(.+)';<br>
<br>
// Fetch file into an array<br>
if(!($file = @file( $url, "r" )))<br>
{<br>
$keywords = 'Not Available';<br>
$description = 'Not Available';<br>
$title = 'Not Available';<br>
}<br>
else<br>
{<br>
// Turn array into a string using a space as the delimiter.<br>
$target = @implode( " ", $file);</p>
<p> // Remove tab, return, and newline characters.<br>
$pat = "\n";<br>
$repl = " ";<br>
$target = ereg_replace($pat, $repl, $target);<br>
$pat = "\t";<br>
$repl = " ";<br>
$target = ereg_replace($pat, $repl, $target);<br>
$pat = "\r";<br>
$repl = " ";<br>
$target = ereg_replace($pat, $repl, $target);</p>
<p> // Evaluate string with regular expression and find match for title.<br>
if(eregi($p_title[0], $target, $match))<br>
{ <br>
$title = $match[2];<br>
}<br>
elseif(eregi($p_title[1], $target, $match))<br>
{<br>
$title = $match[6];<br>
}<br>
elseif(eregi($p_title[2], $target, $match))<br>
{<br>
$title = $match[6];<br>
}<br>
else<br>
{<br>
$title = 'Not Available';<br>
}</p>
<p> // Evaluate string with regular expression and find match for description.<br>
if(eregi($p_description[0], $target, $match))<br>
{ <br>
$description = $match[6];<br>
}<br>
elseif(eregi($p_description[1], $target, $match))<br>
{<br>
$description = $match[6];<br>
}<br>
else<br>
{<br>
$description = 'Not Available';<br>
}</p>
<p> // Evaluate string with regular expression and find match for keywords.<br>
if(eregi($p_keywords[0], $target, $match))<br>
{ <br>
$keywords = $match[6];<br>
}<br>
elseif(eregi($p_keywords[1], $target, $match))<br>
{<br>
$keywords = $match[6];<br>
}<br>
// If no meta tag content is presend for keywords use document text as keywords<br>
// starting after the </head> tag.<br>
elseif(eregi($p_keywords[2], $target, $match))<br>
{<br>
//Remove HTML and PHP tags<br>
$match[2] = strip_tags($match[2]);<br>
//Strip white spaces before and after string<br>
$match[2] = trim($match[2]);<br>
//Limit size of string to 1000 characters starting at the 100th character<br>
$match[2] = substr($match[2], 100, 1100);<br>
$keywords = $match[2];<br>
}<br>
else<br>
{<br>
$keywords = 'Not Available';<br>
}<br>
}</p>
<p> $metatag[title] = $title;<br>
$metatag[description] = $description;<br>
$metatag[keywords] = $keywords;<br>
<br>
return $metatag;<br>
}</p>
<p>?></p>
</body>